Skip to content

RRF/search_logs: eliminate duplicate get_chunks_by_ids round-trip #96

Description

@VarunGitGood

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.pysearch_logs, lines ~66-89.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestreAct improvementImprovements to the ReAct investigation loop / LLM prompt behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions