4a19d70af1
Lint with Ruff / ruff (push) Has been cancelled
MCP Server Tests / live-mcp-tests (push) Has been cancelled
Tests / unit-tests (push) Has been cancelled
Tests / database-integration-tests (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Server Tests / live-server-tests (push) Has been cancelled
Pyright Type Check / pyright (push) Has been cancelled
166 lines
4.4 KiB
Python
166 lines
4.4 KiB
Python
"""
|
|
Copyright 2024, Zep Software, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Any
|
|
|
|
from graphiti_core.driver.query_executor import QueryExecutor
|
|
from graphiti_core.edges import EntityEdge
|
|
from graphiti_core.nodes import CommunityNode, EntityNode, EpisodicNode
|
|
from graphiti_core.search.search_filters import SearchFilters
|
|
|
|
|
|
class SearchOperations(ABC):
|
|
# Node search
|
|
|
|
@abstractmethod
|
|
async def node_fulltext_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
query: str,
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[EntityNode]: ...
|
|
|
|
@abstractmethod
|
|
async def node_similarity_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
search_vector: list[float],
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
min_score: float = 0.6,
|
|
) -> list[EntityNode]: ...
|
|
|
|
@abstractmethod
|
|
async def node_bfs_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
origin_uuids: list[str],
|
|
search_filter: SearchFilters,
|
|
max_depth: int,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[EntityNode]: ...
|
|
|
|
# Edge search
|
|
|
|
@abstractmethod
|
|
async def edge_fulltext_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
query: str,
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[EntityEdge]: ...
|
|
|
|
@abstractmethod
|
|
async def edge_similarity_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
search_vector: list[float],
|
|
source_node_uuid: str | None,
|
|
target_node_uuid: str | None,
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
min_score: float = 0.6,
|
|
) -> list[EntityEdge]: ...
|
|
|
|
@abstractmethod
|
|
async def edge_bfs_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
origin_uuids: list[str],
|
|
max_depth: int,
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[EntityEdge]: ...
|
|
|
|
# Episode search
|
|
|
|
@abstractmethod
|
|
async def episode_fulltext_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
query: str,
|
|
search_filter: SearchFilters,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[EpisodicNode]: ...
|
|
|
|
# Community search
|
|
|
|
@abstractmethod
|
|
async def community_fulltext_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
query: str,
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
) -> list[CommunityNode]: ...
|
|
|
|
@abstractmethod
|
|
async def community_similarity_search(
|
|
self,
|
|
executor: QueryExecutor,
|
|
search_vector: list[float],
|
|
group_ids: list[str] | None = None,
|
|
limit: int = 10,
|
|
min_score: float = 0.6,
|
|
) -> list[CommunityNode]: ...
|
|
|
|
# Rerankers
|
|
|
|
@abstractmethod
|
|
async def node_distance_reranker(
|
|
self,
|
|
executor: QueryExecutor,
|
|
node_uuids: list[str],
|
|
center_node_uuid: str,
|
|
min_score: float = 0,
|
|
) -> list[EntityNode]: ...
|
|
|
|
@abstractmethod
|
|
async def episode_mentions_reranker(
|
|
self,
|
|
executor: QueryExecutor,
|
|
node_uuids: list[str],
|
|
min_score: float = 0,
|
|
) -> list[EntityNode]: ...
|
|
|
|
# Filter builders (sync)
|
|
|
|
@abstractmethod
|
|
def build_node_search_filters(self, search_filters: SearchFilters) -> Any: ...
|
|
|
|
@abstractmethod
|
|
def build_edge_search_filters(self, search_filters: SearchFilters) -> Any: ...
|
|
|
|
# Fulltext query builder
|
|
|
|
@abstractmethod
|
|
def build_fulltext_query(
|
|
self,
|
|
query: str,
|
|
group_ids: list[str] | None = None,
|
|
max_query_length: int = 8000,
|
|
) -> str: ...
|