Repository navigation
Refactor: Drop the vector fetch for ES - #14970
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactors retrieval: defer chunk vector fetching from first-pass ES search to on-demand steps, add ES KNN scoring and vector-fetch helpers, and make dialog citation decoration async to hydrate missing vectors before inserting citations. ChangesDeferred Vector Loading for Search and Citation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14970 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…5390) ### What problem does this PR solve? On the OpenSearch backend (`DOC_ENGINE=opensearch`), every retrieval that performs the KNN second-pass scoring crashes with: AttributeError: 'OSConnection' object has no attribute 'get_scores' **Root cause.** #14970 ("Refactor: Drop the vector fetch for ES") added a `get_scores()` helper to `ESConnectionBase` (`common/doc_store/es_conn_base.py`) and introduced `Dealer._knn_scores()` in `rag/nlp/search.py`, which calls `self.dataStore.get_scores(res)`. `search.py` routes Infinity and OceanBase to their own similarity paths via `DOC_ENGINE_INFINITY` / `DOC_ENGINE_OCEANBASE`, but OpenSearch sets neither flag, so it falls into the Elasticsearch branch and calls `get_scores`. `OSConnection` (which subclasses `DocStoreConnection` directly, not `ESConnectionBase`) never received that method, so any vector-search hit triggers the crash. It reproduces with any normal embedding (e.g. 1024-dim mistral-embed) as soon as a KNN query returns hits. ### Fix Add `OSConnection.get_scores()`, mirroring `ESConnectionBase.get_scores()`. OpenSearch hit headers expose `_score` exactly like Elasticsearch (the existing `OSConnection.__getSource` already reads `d["_score"]`), so the implementation is identical. Scope note: Infinity and OceanBase deliberately do not use `get_scores` (#14970 routes them elsewhere), so this fix is intentionally limited to the OpenSearch backend, which is the only one reaching the ES KNN-score path. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Affected backends OpenSearch only. Elasticsearch already implements `get_scores`; Infinity / OceanBase are routed away from it. ### How to reproduce 1. `DOC_ENGINE=opensearch` (docker `.env`), restart the stack. 2. Create a knowledge base with any dense embedding model and parse a document. 3. Run a retrieval / chat over that KB -> 500 with the AttributeError above. ### Risk & backward compatibility None for the default Elasticsearch deployment -- the change only adds a method to `OSConnection`. No default values or ES/Infinity/OceanBase behavior change. ### Test plan - [ ] With `DOC_ENGINE=opensearch`, retrieval over a KB returns scored chunks (no AttributeError). - [ ] `DOC_ENGINE=elasticsearch` regression: retrieval unchanged. - [ ] Empty-result path: `_knn_scores` early-returns `{}` (guarded), get_scores handles an empty `hits` list gracefully.
…knn boost (#18662) ### Summary Fix OpenSearch retrieval returning `vector_similarity = 0.000` for every chunk when hybrid search is enabled. On the OpenSearch backend, retrieval uses a second KNN-only search (`Dealer._knn_scores()`) to recover per-chunk cosine scores for reranking. That pass intentionally sends `MatchDenseExpr(..., {"similarity": 0.0})` to mean “no minimum similarity cutoff.” However, `OSConnection.search()` was incorrectly mapping `similarity` to the KNN clause `boost` field: ```python knn_query[vector_column_name]["boost"] = similarity ``` With `similarity=0.0`, this produced `boost=0.0`, which zeroed out KNN `_score` values. `get_scores()` then returned `0.0` for every hit, so `vector_similarity` was always zero and hybrid ranking ignored the vector component — with no exception raised. This is separate from the `get_scores()` `AttributeError` crash addressed in #14970 / #15390; here retrieval succeeds but vector scores are silently lost.
Summary
q_*_vec) back from Elasticsearch in the main retrieval path. ES already knows them; shipping them was pure bandwidth/memory overhead._scoreis merged with locally computed term similarity using the user-configuredvector_similarity_weight.insert_citationsactually needs.Details
rag/nlp/search.pyDealer.search: no longer appendsq_*_vecto the ES select list. OceanBase still gets it (its rerank path is unchanged).Dealer._knn_scores(sres, idx_names, kb_ids): aMatchDenseExprover the cached query vector filtered byid IN sres.ids, returning{chunk_id: cosine_score}via ES_score.Dealer.rerank_with_knn(...): term similarity fromqryr.token_similarityplus the ES-supplied KNN score, combined withtkweight/vtweightand the existing rank-feature bonus.Dealer.fetch_chunk_vectors(chunk_ids, tenant_ids, kb_ids, dim): on-demand vector fetch for citation use.Dealer.retrievalroutes Infinity → unchanged, OceanBase → existing localrerank, ES → new KNN-score path.common/doc_store/es_conn_base.pyget_scores(res)helper returning{_id: _score}directly from hit headers (ES doesn't surface_scorethroughget_fields).api/db/services/dialog_service.py_hydrate_chunk_vectors(...)helper. On ES it back-fillsck["vector"]fromfetch_chunk_vectorsright beforeinsert_citations. No-op on Infinity / OB (their chunks already carry vectors).decorate_answerclosures becameasyncand areawait-ed at all call sites inasync_chatandasync_ask.Backend behavior
_score) merged with term sim_scoreTest plan
similarity/vector_similarity/term_similaritypopulated.[ID:n]markers).rerankpath).min_matchfallback paths still pass.