Spaces:
Runtime error
Runtime error
Removed the temporary check and modified stopping criteria for the search.
Browse files- filterminutes.py +2 -3
filterminutes.py
CHANGED
@@ -64,16 +64,15 @@ def search_with_filter(vector_store, query, filter_dict, target_k=5, init_k=100,
|
|
64 |
"""
|
65 |
context = filter_docs_by_meta(vector_store.similarity_search(query, k=init_k), filter_dict)
|
66 |
len_docs_begin = len(context)
|
67 |
-
print('len_docs_begin', len_docs_begin)
|
68 |
if len_docs_begin >= target_k:
|
69 |
log.info(f'Initial search contains {len_docs_begin} Documents. Expansion not required. ')
|
70 |
return context
|
71 |
-
CUT_THE_LOOP_N =
|
72 |
for top_k_docs in np.arange(init_k, CUT_THE_LOOP_N * init_k, step):
|
73 |
log.info(f'Context contains {len(context)} documents')
|
74 |
log.info(f'Expanding search with k={top_k_docs}')
|
75 |
context = filter_docs_by_meta(vector_store.similarity_search(query, k=int(top_k_docs)), filter_dict)
|
76 |
-
if len(context)
|
77 |
log.info(f'Success. Context contains {len(context)} Documents matching the filtering criteria')
|
78 |
return context
|
79 |
log.info(f'Failed to reach target number of documents after {CUT_THE_LOOP_N} loops,'
|
|
|
64 |
"""
|
65 |
context = filter_docs_by_meta(vector_store.similarity_search(query, k=init_k), filter_dict)
|
66 |
len_docs_begin = len(context)
|
|
|
67 |
if len_docs_begin >= target_k:
|
68 |
log.info(f'Initial search contains {len_docs_begin} Documents. Expansion not required. ')
|
69 |
return context
|
70 |
+
CUT_THE_LOOP_N = 500
|
71 |
for top_k_docs in np.arange(init_k, CUT_THE_LOOP_N * init_k, step):
|
72 |
log.info(f'Context contains {len(context)} documents')
|
73 |
log.info(f'Expanding search with k={top_k_docs}')
|
74 |
context = filter_docs_by_meta(vector_store.similarity_search(query, k=int(top_k_docs)), filter_dict)
|
75 |
+
if len(context) >= target_k:
|
76 |
log.info(f'Success. Context contains {len(context)} Documents matching the filtering criteria')
|
77 |
return context
|
78 |
log.info(f'Failed to reach target number of documents after {CUT_THE_LOOP_N} loops,'
|