Skip to content

Commit 4442a5c

Browse files
committed
Replace final_hybrid_stage
1 parent 8420294 commit 4442a5c

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

libs/langchain-mongodb/langchain_mongodb/pipelines.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
from typing import Any, Dict, List, Optional, Union
1111

12-
from pymongo_search_utils import combine_pipelines # noqa: F401
12+
from pymongo_search_utils import (
13+
combine_pipelines, # noqa: F401
14+
final_hybrid_stage, # noqa: F401
15+
)
1316

1417

1518
def text_search_stage(
@@ -129,26 +132,3 @@ def reciprocal_rank_stage(
129132
},
130133
{"$replaceRoot": {"newRoot": "$docs"}},
131134
]
132-
133-
134-
def final_hybrid_stage(
135-
scores_fields: List[str], limit: int, **kwargs: Any
136-
) -> List[Dict[str, Any]]:
137-
"""Sum weighted scores, sort, and apply limit.
138-
139-
Args:
140-
scores_fields: List of fields given to scores of vector and text searches
141-
limit: Number of documents to return
142-
143-
Returns:
144-
Final aggregation stages
145-
"""
146-
147-
return [
148-
{"$group": {"_id": "$_id", "docs": {"$mergeObjects": "$$ROOT"}}},
149-
{"$replaceRoot": {"newRoot": "$docs"}},
150-
{"$set": {score: {"$ifNull": [f"${score}", 0]} for score in scores_fields}},
151-
{"$addFields": {"score": {"$add": [f"${score}" for score in scores_fields]}}},
152-
{"$sort": {"score": -1}},
153-
{"$limit": limit},
154-
]

0 commit comments

Comments
 (0)