fix(retrieval): return no matches instead of erroring when the vector collection doesn't exist yet - #843
fix(retrieval): return no matches instead of erroring when the vector collection doesn't exist yet#843EnjoyBacon7 wants to merge 1 commit into
Conversation
… collection doesn't exist yet The shared Milvus collection is created lazily on the first indexed file system-wide. On a fresh deployment, or any query before that first index, search/multi_query_search raised CollectionNotExists -> VDBSearchError instead of returning an empty result — the same class of bug #508 already fixed for delete_partition.
📝 WalkthroughWalkthroughThe vector-store search methods now check collection existence before embedding or retrieval. Missing collections return empty results. Unit tests cover both search methods and update existing mocks for the collection-present path. ChangesVector collection guard
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openrag/services/storage/vector_store_searcher.py`:
- Around line 72-74: Update the search flow in VectorStoreSearcher to handle a
collection being dropped between collection_exists() and search(). Prefer an
atomic store-level search operation; otherwise catch the store’s
missing-collection error around search and return [] while preserving
VDBSearchError translation for other failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 74edc257-317a-4801-9533-ae2ba9ffc389
📒 Files selected for processing (2)
openrag/services/storage/vector_store_searcher.pytests/unit/services/storage/test_vector_store_searcher.py
| # Collection is created lazily on first insert (#508); absent means no chunks. | ||
| if not await self._store.collection_exists(self._collection): | ||
| return [] |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Expect either no concurrent collection-drop path or explicit missing-collection handling.
rg -n -C 8 'drop_collection|release_collection|has_collection|collection_exists|VDBSearchError' openrag testsRepository: linagora/openrag
Length of output: 50372
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Inspect the relevant searcher/store implementation and exception shape without running repo code.
sed -n '1,150p' openrag/services/storage/vector_store_searcher.py
printf '\n--- exceptions around VDBSearchError / VDBPartitionNotFound ---\n'
sed -n '35,46p' openrag/core/utils/exceptions.py
sed -n '400,412p' openrag/core/utils/exceptions.py
printf '\n--- Milvus search wrappers and collection drop/resolvers ---\n'
sed -n '800,1105p' openrag/services/storage/milvus_store.py
sed -n '880,980p' openrag/services/storage/milvus_store.pyRepository: linagora/openrag
Length of output: 23633
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Find all search_call sites around collection_exists and whether they catch missing-collection errors.
rg -n -C 4 'collection_exists\(.*collection|\.search\(|\.hybrid_search\(' openrag/services/storage/vector_store_searcher.py openrag/services/storage/milvus_store.py tests/integration/repos/test_milvus_store_integration.py tests/integration/repos/test_workspace_scoping_e2e.pyRepository: linagora/openrag
Length of output: 12540
Handle collection absence atomically in search.
collection_exists() and search() are separate calls. If drop_collection() runs concurrently, search() can still translate the missing collection failure to VDBSearchError. Make the store operation atomic, or catch the missing-collection state at VectorStoreSearcher and return an empty result.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@openrag/services/storage/vector_store_searcher.py` around lines 72 - 74,
Update the search flow in VectorStoreSearcher to handle a collection being
dropped between collection_exists() and search(). Prefer an atomic store-level
search operation; otherwise catch the store’s missing-collection error around
search and return [] while preserving VDBSearchError translation for other
failures.
What
search()/multi_query_search()onVectorStoreSearcherraise instead ofreturning an empty result when the shared Milvus collection doesn't exist yet.
Root cause
The shared collection (
config.vectordb.collection_name) is created lazilyon the first indexed file system-wide (
services/workers/stages/store.py).On a fresh deployment — or any retrieval-needing chat/search query before
that first file is indexed, regardless of partition — Milvus raises
CollectionNotExists, wrapped asVDBSearchError, and propagates as a realerror instead of "no matches."
This is the same class of bug #508 already fixed for
delete_partition(
PartitionService), using the existingVectorStore.collection_exists()port method as the guard. That fix only covered delete; search was still
exposed.
Fix
Mirror #508's pattern in
VectorStoreSearcher.search()andmulti_query_search(): checkcollection_exists()before embedding/searching, and return
[]immediately if the collection is absent — nocollection means no chunks to find, and skipping straight to an empty result
also avoids an unnecessary embedding-API call.
Test
Adds
test_search_returns_empty_when_collection_does_not_existandtest_multi_query_search_returns_empty_when_collection_does_not_exist,asserting the embedder and store are never called when the collection is
absent. Full unit suite: 2433 passed (1 pre-existing unrelated failure on
develop, unaffected by this change), ruff clean, layer-import guard clean.Summary by CodeRabbit
Bug Fixes
Tests