parent
d725fcdf8e
commit
36056ad141
5 changed files with 57 additions and 20 deletions
|
|
@ -312,9 +312,11 @@ class GraphDriver(ABC):
|
|||
|
||||
return 0
|
||||
|
||||
def build_fulltext_query(self, query: str, group_ids: list[str] | None = None, max_query_length: int = 128) -> str:
|
||||
def build_fulltext_query(
|
||||
self, query: str, group_ids: list[str] | None = None, max_query_length: int = 128
|
||||
) -> str:
|
||||
"""
|
||||
Specific fulltext query builder for database providers.
|
||||
Only implemented by providers that need custom fulltext query building.
|
||||
"""
|
||||
raise NotImplementedError(f"build_fulltext_query not implemented for {self.provider}")
|
||||
raise NotImplementedError(f'build_fulltext_query not implemented for {self.provider}')
|
||||
|
|
|
|||
|
|
@ -37,11 +37,42 @@ from graphiti_core.utils.datetime_utils import convert_datetimes_to_strings
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
STOPWORDS = [
|
||||
'a', 'is', 'the', 'an', 'and', 'are', 'as', 'at', 'be', 'but', 'by', 'for',
|
||||
'if', 'in', 'into', 'it', 'no', 'not', 'of', 'on', 'or', 'such', 'that', 'their',
|
||||
'then', 'there', 'these', 'they', 'this', 'to', 'was', 'will', 'with'
|
||||
'a',
|
||||
'is',
|
||||
'the',
|
||||
'an',
|
||||
'and',
|
||||
'are',
|
||||
'as',
|
||||
'at',
|
||||
'be',
|
||||
'but',
|
||||
'by',
|
||||
'for',
|
||||
'if',
|
||||
'in',
|
||||
'into',
|
||||
'it',
|
||||
'no',
|
||||
'not',
|
||||
'of',
|
||||
'on',
|
||||
'or',
|
||||
'such',
|
||||
'that',
|
||||
'their',
|
||||
'then',
|
||||
'there',
|
||||
'these',
|
||||
'they',
|
||||
'this',
|
||||
'to',
|
||||
'was',
|
||||
'will',
|
||||
'with',
|
||||
]
|
||||
|
||||
|
||||
class FalkorDriverSession(GraphDriverSession):
|
||||
provider = GraphProvider.FALKORDB
|
||||
|
||||
|
|
@ -173,7 +204,6 @@ class FalkorDriver(GraphDriver):
|
|||
|
||||
return cloned
|
||||
|
||||
|
||||
def sanitize(self, query: str) -> str:
|
||||
"""
|
||||
Replace FalkorDB special characters with whitespace.
|
||||
|
|
@ -216,7 +246,9 @@ class FalkorDriver(GraphDriver):
|
|||
sanitized = ' '.join(sanitized.split())
|
||||
return sanitized
|
||||
|
||||
def build_fulltext_query(self, query: str, group_ids: list[str] | None = None, max_query_length: int = 128) -> str:
|
||||
def build_fulltext_query(
|
||||
self, query: str, group_ids: list[str] | None = None, max_query_length: int = 128
|
||||
) -> str:
|
||||
"""
|
||||
Build a fulltext query string for FalkorDB using RedisSearch syntax.
|
||||
FalkorDB uses RedisSearch-like syntax where:
|
||||
|
|
@ -230,7 +262,7 @@ class FalkorDriver(GraphDriver):
|
|||
group_filter = ''
|
||||
else:
|
||||
group_values = '|'.join(group_ids)
|
||||
group_filter = f"(@group_id:{group_values})"
|
||||
group_filter = f'(@group_id:{group_values})'
|
||||
|
||||
sanitized_query = self.sanitize(query)
|
||||
|
||||
|
|
@ -245,4 +277,4 @@ class FalkorDriver(GraphDriver):
|
|||
|
||||
full_query = group_filter + ' (' + sanitized_query + ')'
|
||||
|
||||
return full_query
|
||||
return full_query
|
||||
|
|
|
|||
|
|
@ -72,37 +72,40 @@ def get_range_indices(provider: GraphProvider) -> list[LiteralString]:
|
|||
def get_fulltext_indices(provider: GraphProvider) -> list[LiteralString]:
|
||||
if provider == GraphProvider.FALKORDB:
|
||||
from typing import cast
|
||||
|
||||
|
||||
from graphiti_core.driver.falkordb_driver import STOPWORDS
|
||||
|
||||
|
||||
# Convert to string representation for embedding in queries
|
||||
stopwords_str = str(STOPWORDS)
|
||||
|
||||
|
||||
# Use type: ignore to satisfy LiteralString requirement while maintaining single source of truth
|
||||
return cast(list[LiteralString], [
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
return cast(
|
||||
list[LiteralString],
|
||||
[
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
{{
|
||||
label: 'Episodic',
|
||||
stopwords: {stopwords_str}
|
||||
}},
|
||||
'content', 'source', 'source_description', 'group_id'
|
||||
)""",
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
{{
|
||||
label: 'Entity',
|
||||
stopwords: {stopwords_str}
|
||||
}},
|
||||
'name', 'summary', 'group_id'
|
||||
)""",
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
f"""CALL db.idx.fulltext.createNodeIndex(
|
||||
{{
|
||||
label: 'Community',
|
||||
stopwords: {stopwords_str}
|
||||
}},
|
||||
'name', 'group_id'
|
||||
)""",
|
||||
"""CREATE FULLTEXT INDEX FOR ()-[e:RELATES_TO]-() ON (e.name, e.fact, e.group_id)""",
|
||||
])
|
||||
"""CREATE FULLTEXT INDEX FOR ()-[e:RELATES_TO]-() ON (e.name, e.fact, e.group_id)""",
|
||||
],
|
||||
)
|
||||
|
||||
if provider == GraphProvider.KUZU:
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[project]
|
||||
name = "graphiti-core"
|
||||
description = "A temporal graph building library"
|
||||
version = "0.21.0pre3"
|
||||
version = "0.21.0pre4"
|
||||
authors = [
|
||||
{ name = "Paul Paliychuk", email = "paul@getzep.com" },
|
||||
{ name = "Preston Rasmussen", email = "preston@getzep.com" },
|
||||
|
|
|
|||
2
uv.lock
generated
2
uv.lock
generated
|
|
@ -783,7 +783,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "graphiti-core"
|
||||
version = "0.21.0rc3"
|
||||
version = "0.21.0rc4"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "diskcache" },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue