feat(oss): port v3 pipeline with hybrid search, entity extraction, and additive scoring (#4805)

Co-authored-by: Soumil Rathi <soumilrathi@gmail.com>
Co-authored-by: Saket Aryan <saketaryan2002@gmail.com>
Co-authored-by: chaithanyak42 <chaithanya.kumar42a@gmail.com>
Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
soumil-rathi
2026-04-14 18:00:58 +05:30
committed by GitHub
co-authored by Soumil Rathi Saket Aryan chaithanyak42 kartik-mem0
parent 57f944e18a
commit a488e19044
120 changed files with 10107 additions and 17135 deletions
+51
View File
@@ -203,6 +203,57 @@ class OpenSearchDB(VectorStoreBase):
logger.error(f"Error during search: {e}", exc_info=True)
return []
def keyword_search(self, query, top_k=5, filters=None):
"""Search for memories using BM25 keyword matching.
Args:
query (str): The text query to search for.
top_k (int): Maximum number of results to return. Defaults to 5.
filters (Dict, optional): Filters to apply to the search.
Returns:
List[OutputData]: Search results with id, score, and payload.
"""
# Build a multi_match query across text fields in payload
should_clauses = [
{"match": {"payload.data": query}},
{"match": {"payload.text_lemmatized": query}},
]
bool_query = {
"should": should_clauses,
"minimum_should_match": 1,
}
# Apply filters consistently with the existing search() method
filter_clauses = []
if filters:
for key in ["user_id", "run_id", "agent_id"]:
value = filters.get(key)
if value:
filter_clauses.append({"term": {f"payload.{key}.keyword": value}})
if filter_clauses:
bool_query["filter"] = filter_clauses
query_body = {
"size": top_k,
"query": {"bool": bool_query},
}
try:
response = self.client.search(index=self.collection_name, body=query_body)
hits = response["hits"]["hits"]
results = [
OutputData(id=hit["_source"].get("id"), score=hit["_score"], payload=hit["_source"].get("payload", {}))
for hit in hits[:top_k]
]
return results
except Exception as e:
logger.error(f"Error during keyword search: {e}")
return []
def delete(self, vector_id: str) -> None:
"""Delete a vector by custom ID."""
# First, find the document by custom ID