Why
A single search_logs call can hit get_chunks_by_ids twice for overlapping IDs.
When ENABLE_LEVEL_BOOST=True (the default) or recency_boost=True, _rrf already fetches chunk metadata for the whole candidate pool to apply the boost:
# repi/retrieval/rrf.py:128-133
level_boost = settings.ENABLE_LEVEL_BOOST
need_meta = recency_boost or level_boost
if need_meta and rrf_scores:
chunk_ids = list(rrf_scores.keys())
chunks_data = await self.vector_store.get_chunks_by_ids(chunk_ids)
Then search_logs re-fetches metadata for the returned IDs:
# repi/investigation/tools.py:72-73
chunk_ids = [res[0] for res in results]
chunks_data = await rrf_service.vector_store.get_chunks_by_ids(chunk_ids)
The second fetch is a subset of the first (final top_k ⊆ candidate pool), so it is a redundant DB round-trip on the default config. With level boost on, every search_logs pays for two trips where one would do.
Scope (in)
- Have the RRF layer return the metadata it already fetched, so
search_logs reuses it instead of re-querying.
- Suggested approach: add a method (e.g.
search_with_meta) that returns (ranked, chunks_data), or have search_logs call a path that surfaces chunks_data. Keep the existing search/search_diverse signatures intact for back-compat.
- When
need_meta is False (boosts disabled), _rrf fetches nothing — search_logs must still fetch in that case. Handle both paths.
Scope (out)
- Changing the boost logic or the public
search/search_diverse return types.
Acceptance
- With
ENABLE_LEVEL_BOOST=True, a search_logs call issues one get_chunks_by_ids round-trip, verified by a unit test that counts calls on a mocked vector store.
- Output of
search_logs is unchanged.
Files
repi/retrieval/rrf.py
repi/investigation/tools.py — search_logs, lines ~66-89.
Why
A single
search_logscall can hitget_chunks_by_idstwice for overlapping IDs.When
ENABLE_LEVEL_BOOST=True(the default) orrecency_boost=True,_rrfalready fetches chunk metadata for the whole candidate pool to apply the boost:Then
search_logsre-fetches metadata for the returned IDs:The second fetch is a subset of the first (final top_k ⊆ candidate pool), so it is a redundant DB round-trip on the default config. With level boost on, every
search_logspays for two trips where one would do.Scope (in)
search_logsreuses it instead of re-querying.search_with_meta) that returns(ranked, chunks_data), or havesearch_logscall a path that surfaceschunks_data. Keep the existingsearch/search_diversesignatures intact for back-compat.need_metaisFalse(boosts disabled),_rrffetches nothing —search_logsmust still fetch in that case. Handle both paths.Scope (out)
search/search_diversereturn types.Acceptance
ENABLE_LEVEL_BOOST=True, asearch_logscall issues oneget_chunks_by_idsround-trip, verified by a unit test that counts calls on a mocked vector store.search_logsis unchanged.Files
repi/retrieval/rrf.pyrepi/investigation/tools.py—search_logs, lines ~66-89.