Skip to content

test(rag): direct coverage for knowledge_store_rag._run() (#442)#455

Open
mayoka0 wants to merge 1 commit into
Lamb-Project:feat/ks-vector-indexing-labelfrom
mayoka0:test/issue-442-knowledge-store-rag-run-coverage
Open

test(rag): direct coverage for knowledge_store_rag._run() (#442)#455
mayoka0 wants to merge 1 commit into
Lamb-Project:feat/ks-vector-indexing-labelfrom
mayoka0:test/issue-442-knowledge-store-rag-run-coverage

Conversation

@mayoka0

@mayoka0 mayoka0 commented Jun 26, 2026

Copy link
Copy Markdown

Closes #442.

What

Adds backend/tests/test_knowledge_store_rag.py — a focused, test-only module that exercises knowledge_store_rag._run() directly. Previously only the helpers (_ks_query_helpers, query_rewriting_ks_rag) were covered, leaving _run()'s guard branches, multi-KS fan-out, per-store error handling, and context/source assembly untested.

No production code is touched.

Base branch

The knowledge_store_rag.py processor and its helpers live on feat/ks-vector-indexing-label, not main, so this PR targets that branch (the existing tests/test_query_rewriting_ks_rag.py lives there too). Happy to retarget if you'd prefer it elsewhere.

Coverage (10 tests)

Mirrors the patch-query_one_ks pattern of the existing test_query_rewriting_ks_rag.py (real Assistant, AsyncMocked query_one_ks, real serialize_assistant / _extract_sources):

  • Guard branches — missing assistant, empty RAG_collections, no user message, separator-only RAG_collections
  • Success path — single-KS context + source assembly, raw_responses, assistant_data
  • Query construction — last user message is used; top_k and owner forwarded verbatim
  • Multi-KS fan-out — every configured KS is queried; contexts and sources aggregated
  • Per-store error handling — a failing KS is logged/skipped without sinking a healthy one; all-failing yields empty context
  • Assembly edge — an empty-text chunk is still surfaced as a source but omitted from the combined context

Note on the issue description

The issue mentions a [N]-numbered context. The current _run() joins chunk texts with \n\n (no [N] prefixes), so the tests assert the actual combined-context + aligned-sources behaviour rather than numbering. If [N] numbering is the intended direction, that's a small production change I'm happy to follow up with in a separate PR.

Testing

asyncio_mode = auto (per backend/pytest.ini), so:

cd backend && python3 -m pytest tests/test_knowledge_store_rag.py -v

All 10 pass locally.

— Contributed by Mayoka Labs

…roject#442)

The knowledge_store_rag processor is the primary retrieval entry point for
Knowledge Store assistants, but only its helpers were covered. _run() itself —
the guard branches, multi-KS fan-out, per-store error handling, and the
context/source assembly — had no direct test.

Adds tests/test_knowledge_store_rag.py (10 tests, test-only, no production
changes), mirroring the patch-query_one_ks pattern of the existing
test_query_rewriting_ks_rag.py:

  - guard branches: no assistant, empty RAG_collections, no user message,
    separator-only RAG_collections
  - success path: single-KS context + source assembly, raw_responses,
    assistant_data
  - query construction: last user message used; top_k and owner forwarded
  - multi-KS fan-out: every KS queried, contexts/sources aggregated
  - per-store error handling: a failing KS is skipped without sinking a
    healthy one; all-failing yields empty context
  - assembly edge: empty-text chunk is sourced but omitted from context

Contributed by Mayoka Labs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant