Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/memos/graph_dbs/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,26 @@ def search_by_embedding(

return records

def search_by_fulltext(
self,
query_words: list[str],
top_k: int = 10,
scope: str | None = None,
status: str | None = None,
threshold: float | None = None,
search_filter: dict | None = None,
user_name: str | None = None,
filter: dict | None = None,
knowledgebase_ids: list[str] | None = None,
tsquery_config: str | None = None,
**kwargs,
) -> list[dict]:
"""
TODO: 实现 Neo4j 的关键词检索, 以兼容 TreeTextMemory 的 keyword/fulltext 召回路径.
目前先返回空列表, 避免切换到 Neo4j 后因缺失方法导致运行时报错.
"""
return []

def get_by_metadata(
self,
filters: list[dict[str, Any]],
Expand Down
20 changes: 20 additions & 0 deletions src/memos/graph_dbs/neo4j_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,26 @@ def search_by_embedding(

return filtered_results

def search_by_fulltext(
self,
query_words: list[str],
top_k: int = 10,
scope: str | None = None,
status: str | None = None,
threshold: float | None = None,
search_filter: dict | None = None,
user_name: str | None = None,
filter: dict | None = None,
knowledgebase_ids: list[str] | None = None,
tsquery_config: str | None = None,
**kwargs,
) -> list[dict]:
"""
TODO: 实现 Neo4j Community 的关键词检索, 以兼容 TreeTextMemory 的 keyword/fulltext 召回路径.
目前先返回空列表, 避免切换到 Neo4j 后因缺失方法导致运行时报错.
"""
return []

def _normalize_date_string(self, date_str: str) -> str:
"""
Normalize date string to ISO 8601 format for Neo4j datetime() function.
Expand Down
26 changes: 16 additions & 10 deletions src/memos/memories/textual/tree_text_memory/retrieve/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,22 @@ def _retrieve_from_keyword(

id_to_score: dict[str, float] = {}
for scope in scopes:
hits = self.graph_store.search_by_fulltext(
query_words=tsquery_terms,
top_k=top_k * 2,
status="activated",
scope=scope,
search_filter=None,
filter=search_filter,
user_name=user_name,
tsquery_config="jiebaqry",
)
try:
hits = self.graph_store.search_by_fulltext(
query_words=tsquery_terms,
top_k=top_k * 2,
status="activated",
scope=scope,
search_filter=None,
filter=search_filter,
user_name=user_name,
tsquery_config="jiebaqry",
)
except Exception as e:
logger.warning(
f"[PATH-KEYWORD] search_by_fulltext failed, scope={scope}, user_name={user_name}"
)
hits = []
for h in hits or []:
hid = str(h.get("id") or "").strip().strip("'\"")
if not hid:
Expand Down