Skip to content

Commit

Permalink
update lucene search (#193)
Browse files Browse the repository at this point in the history
* update lucene search

* update max query length

* bump version
  • Loading branch information
prasmussen15 authored Oct 20, 2024
1 parent 737a3bc commit ecb7043
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion graphiti_core/search/search_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
RELEVANT_SCHEMA_LIMIT = 3
DEFAULT_MIN_SCORE = 0.6
DEFAULT_MMR_LAMBDA = 0.5
MAX_QUERY_LENGTH = 512


def fulltext_query(query: str, group_ids: list[str] | None = None):
Expand All @@ -50,7 +51,11 @@ def fulltext_query(query: str, group_ids: list[str] | None = None):
group_ids_filter += ' AND ' if group_ids_filter else ''

lucene_query = lucene_sanitize(query)
full_query = group_ids_filter + lucene_query
# If the lucene query is too long return no query
if len(lucene_query.split(' ')) + len(group_ids or '') >= MAX_QUERY_LENGTH:
return ''

full_query = group_ids_filter + '(' + lucene_query + ')'

return full_query

Expand Down Expand Up @@ -126,6 +131,8 @@ async def edge_fulltext_search(
) -> list[EntityEdge]:
# fulltext search over facts
fuzzy_query = fulltext_query(query, group_ids)
if fuzzy_query == '':
return []

cypher_query = Query("""
CALL db.index.fulltext.queryRelationships("edge_name_and_fact", $query)
Expand Down Expand Up @@ -219,6 +226,8 @@ async def node_fulltext_search(
) -> list[EntityNode]:
# BM25 search to get top nodes
fuzzy_query = fulltext_query(query, group_ids)
if fuzzy_query == '':
return []

records, _, _ = await driver.execute_query(
"""
Expand Down Expand Up @@ -286,6 +295,8 @@ async def community_fulltext_search(
) -> list[CommunityNode]:
# BM25 search to get top communities
fuzzy_query = fulltext_query(query, group_ids)
if fuzzy_query == '':
return []

records, _, _ = await driver.execute_query(
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "graphiti-core"
version = "0.3.12"
version = "0.3.13"
description = "A temporal graph building library"
authors = [
"Paul Paliychuk <paul@getzep.com>",
Expand Down

0 comments on commit ecb7043

Please sign in to comment.