-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Critical - P2
-
None
-
Affects Version/s: None
-
Component/s: ABX
-
None
Summary
Integration tests in langchain-mongodb query Atlas Search fulltext indexes before mongot has indexed the documents the fixtures just inserted.
Cause
The collection fixtures create indexes under a guard:
if not any(SEARCH_INDEX_NAME == ix["name"] for ix in clxn.list_search_indexes()): create_fulltext_search_index(..., wait_until_complete=TIMEOUT)
The index survives between runs, so the guard is false on every run after the first, and the only wait_until_complete call is skipped. Even on the first run, wait_until_complete waits for index creation, not for documents inserted later.
The vectorstore fixtures then insert documents. PatchedMongoDBAtlasVectorSearch polls the vector index only. Nothing waits for the fulltext index.
Effect
Affected tests see an empty fulltext result set:
- test_rerank.py: test_fulltext_retriever_rerank, test_hybrid_retriever_rerank
- test_retrievers.py: test_hybrid_retriever, test_hybrid_retriever_autoembed, test_hybrid_retriever_deprecated_top_k, test_hybrid_retriever_nested, test_hybrid_search_weighted_rrf
test_hybrid_search_weighted_rrf fails deterministically on assert single_text_score > 0. test_hybrid_retriever_nested is masked by @flaky(max_runs=5, min_passes=4). The hybrid tests degrade to vector-only ranking and fail their ordering assertions.
test_retrievers.py::test_fulltext_retriever carries an inline wait loop, but it runs after every hybrid test in the file, so it protects nothing else.
These failures force full-suite retries in execute-tests.sh (MAX_ATTEMPTS=3) and contribute to test-langchain-python-remote exceeding exec_timeout_secs: 3600.
Fix
Add wait_for_fulltext_index(collection, index_name, path, timeout) to tests/utils.py. It polls a $search with the exists operator and $count until the count matches collection.count_documents({}).
Expose it through per-collection pytest fixtures and add those fixtures to every test that depends on a fulltext index. Replace the inline loop in test_fulltext_retriever with the fixture.
Do not change PatchedMongoDBAtlasVectorSearch and do not change the existing vector wait.
- related to
-
PYTHON-6095 drop_vector_search_index waits for zero search indexes, not the dropped index
-
- In Code Review
-