From f4dc7e2fba1e354bc0aee5bd8311cf4e64da1a5f Mon Sep 17 00:00:00 2001 From: prestonrasmussen Date: Mon, 21 Jul 2025 19:39:31 -0400 Subject: [PATCH] update max query length --- graphiti_core/driver/driver.py | 4 +++- graphiti_core/driver/falkordb_driver.py | 1 - graphiti_core/helpers.py | 2 ++ graphiti_core/search/search_utils.py | 26 +++++++++++++------------ pyproject.toml | 2 +- uv.lock | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/graphiti_core/driver/driver.py b/graphiti_core/driver/driver.py index 7be689b4..9c8f1642 100644 --- a/graphiti_core/driver/driver.py +++ b/graphiti_core/driver/driver.py @@ -46,7 +46,9 @@ class GraphDriverSession(ABC): class GraphDriver(ABC): provider: str - fulltext_syntax: str = '' # Neo4j (default) syntax does not require a prefix for fulltext queries + fulltext_syntax: str = ( + '' # Neo4j (default) syntax does not require a prefix for fulltext queries + ) @abstractmethod def execute_query(self, cypher_query_: str, **kwargs: Any) -> Coroutine: diff --git a/graphiti_core/driver/falkordb_driver.py b/graphiti_core/driver/falkordb_driver.py index ed7431e9..ac71c402 100644 --- a/graphiti_core/driver/falkordb_driver.py +++ b/graphiti_core/driver/falkordb_driver.py @@ -98,7 +98,6 @@ class FalkorDriver(GraphDriver): self._database = database self.fulltext_syntax = '@' # FalkorDB uses a redisearch-like syntax for fulltext queries see https://redis.io/docs/latest/develop/ai/search-and-query/query/full-text/ - def _get_graph(self, graph_name: str | None) -> FalkorGraph: # FalkorDB requires a non-None database name for multi-tenant graphs; the default is "default_db" diff --git a/graphiti_core/helpers.py b/graphiti_core/helpers.py index 855b364d..ae311a08 100644 --- a/graphiti_core/helpers.py +++ b/graphiti_core/helpers.py @@ -51,6 +51,7 @@ def parse_db_date(neo_date: neo4j_time.DateTime | str | None) -> datetime | None else None ) + def get_default_group_id(db_type: str) -> str: """ This function differentiates the default group id based on the database type. @@ -61,6 +62,7 @@ def get_default_group_id(db_type: str) -> str: else: return '' + def lucene_sanitize(query: str) -> str: # Escape special characters from a query before passing into Lucene # + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / diff --git a/graphiti_core/search/search_utils.py b/graphiti_core/search/search_utils.py index f5eab407..79f7081f 100644 --- a/graphiti_core/search/search_utils.py +++ b/graphiti_core/search/search_utils.py @@ -57,12 +57,14 @@ RELEVANT_SCHEMA_LIMIT = 10 DEFAULT_MIN_SCORE = 0.6 DEFAULT_MMR_LAMBDA = 0.5 MAX_SEARCH_DEPTH = 3 -MAX_QUERY_LENGTH = 32 +MAX_QUERY_LENGTH = 128 def fulltext_query(query: str, group_ids: list[str] | None = None, fulltext_syntax: str = ''): group_ids_filter_list = ( - [fulltext_syntax + f"group_id:'{lucene_sanitize(g)}'" for g in group_ids] if group_ids is not None else [] + [fulltext_syntax + f"group_id:'{lucene_sanitize(g)}'" for g in group_ids] + if group_ids is not None + else [] ) group_ids_filter = '' for f in group_ids_filter_list: @@ -293,12 +295,12 @@ async def edge_bfs_search( query = ( """ - UNWIND $bfs_origin_node_uuids AS origin_uuid - MATCH path = (origin:Entity|Episodic {uuid: origin_uuid})-[:RELATES_TO|MENTIONS]->{1,3}(n:Entity) - UNWIND relationships(path) AS rel - MATCH (n:Entity)-[r:RELATES_TO]-(m:Entity) - WHERE r.uuid = rel.uuid - """ + UNWIND $bfs_origin_node_uuids AS origin_uuid + MATCH path = (origin:Entity|Episodic {uuid: origin_uuid})-[:RELATES_TO|MENTIONS]->{1,3}(n:Entity) + UNWIND relationships(path) AS rel + MATCH (n:Entity)-[r:RELATES_TO]-(m:Entity) + WHERE r.uuid = rel.uuid + """ + filter_query + """ RETURN DISTINCT @@ -441,10 +443,10 @@ async def node_bfs_search( query = ( """ - UNWIND $bfs_origin_node_uuids AS origin_uuid - MATCH (origin:Entity|Episodic {uuid: origin_uuid})-[:RELATES_TO|MENTIONS]->{1,3}(n:Entity) - WHERE n.group_id = origin.group_id - """ + UNWIND $bfs_origin_node_uuids AS origin_uuid + MATCH (origin:Entity|Episodic {uuid: origin_uuid})-[:RELATES_TO|MENTIONS]->{1,3}(n:Entity) + WHERE n.group_id = origin.group_id + """ + filter_query + ENTITY_NODE_RETURN + """ diff --git a/pyproject.toml b/pyproject.toml index 841dddd5..29bc6d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "graphiti-core" description = "A temporal graph building library" -version = "0.17.6" +version = "0.17.7" authors = [ { "name" = "Paul Paliychuk", "email" = "paul@getzep.com" }, { "name" = "Preston Rasmussen", "email" = "preston@getzep.com" }, diff --git a/uv.lock b/uv.lock index 9842f430..e4bbec15 100644 --- a/uv.lock +++ b/uv.lock @@ -746,7 +746,7 @@ wheels = [ [[package]] name = "graphiti-core" -version = "0.17.5" +version = "0.17.6" source = { editable = "." } dependencies = [ { name = "diskcache" },