Spaces:
Runtime error
Runtime error
cache BM25
Browse files
core/collection_router_retriever.py
CHANGED
|
@@ -187,8 +187,16 @@ class CollectionRouterRetriever:
|
|
| 187 |
if not docs_from_collection:
|
| 188 |
continue
|
| 189 |
|
| 190 |
-
#
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
bm25_rank = 0
|
| 194 |
for doc in bm25_results:
|
|
|
|
| 187 |
if not docs_from_collection:
|
| 188 |
continue
|
| 189 |
|
| 190 |
+
# Extract content strings for BM25 scoring
|
| 191 |
+
content_for_bm25 = [doc.page_content for doc in docs_from_collection]
|
| 192 |
+
|
| 193 |
+
# Build BM25 index for this subset and score
|
| 194 |
+
if content_for_bm25:
|
| 195 |
+
tokenized_subset = [content.lower().split() for content in content_for_bm25]
|
| 196 |
+
bm25_subset = BM25Okapi(tokenized_subset, k1=1.5, b=0.5)
|
| 197 |
+
bm25_results = bm25_subset.get_top_n(tokenized_query, content_for_bm25, n=len(content_for_bm25))
|
| 198 |
+
else:
|
| 199 |
+
bm25_results = []
|
| 200 |
|
| 201 |
bm25_rank = 0
|
| 202 |
for doc in bm25_results:
|