Repository navigation
feat: implement full retrieval contract and RAGAS evaluation - #1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Implements the “Retrieval V2” contract end-to-end (option resolution, vector/full-text/hybrid execution, filtering/hydration semantics, and per-stage scoring) and adds an offline evaluation layer (deterministic metrics + optional RAGAS runner), including migration, docs, and CI checks.
Changes:
- Added explicit retrieval modes (
vector,full_text,hybrid,auto) with effective option resolution and validation. - Implemented PostgreSQL full-text retrieval + filtered hydration, plus hybrid concurrency and weighted RRF fusion with per-stage score/method tracking.
- Added deterministic retrieval metrics and an optional HTTP evaluation runner with a CI contract workflow and supporting documentation/config.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_retrieval_pipeline.py | Verifies retrieval mode execution, filter propagation, and rerank/rewrite usage with effective options. |
| tests/test_retrieval_options.py | Covers resolver behavior for defaults, overrides, hybrid normalization, and validation errors. |
| tests/test_lexical_retrieval.py | Tests full-text SQL filtering and stable hydration ordering. |
| tests/test_evaluation_metrics.py | Validates deterministic Hit Rate/Precision/Recall/MRR metric behavior. |
| tests/test_database_session.py | Verifies request-scoped commit/rollback behavior for DB sessions. |
| rag/storage/milvus_store.py | Adds document ID filtering to Milvus search and propagates stage scores/methods. |
| rag/schemas.py | Extends schemas for retrieval_mode, filters model, effective_options, and per-stage scoring fields. |
| rag/retrieval/postgres_store.py | Introduces PostgreSQL full-text retrieval and ordered hydration with document/metadata filters. |
| rag/retrieval/pipeline.py | Orchestrates effective options, hybrid concurrency, fusion, hydration, rerank, and response diagnostics. |
| rag/retrieval/options.py | Adds effective option model + resolver mapping modes/booleans/defaults into a validated configuration. |
| rag/retrieval/fusion.py | Implements weighted RRF fusion and carries per-stage methods/scores into fused results. |
| rag/evaluation/runner.py | Adds JSONL-driven offline runner calling the real API and optionally scoring with RAGAS. |
| rag/evaluation/deterministic_metrics.py | Implements deterministic retrieval metrics used by the runner. |
| rag/evaluation/client.py | Adds an HTTP client wrapper for calling the retrieval endpoint during evaluation. |
| rag/evaluation/init.py | Declares evaluation package purpose. |
| pyproject.toml | Adds optional eval dependency group and includes evaluation package. |
| migrations/versions/0004_retrieval_v2.py | Adds JSONB metadata + generated search_vector and indexes for retrieval v2. |
| evals/datasets/smoke.jsonl | Adds a template evaluation dataset case. |
| docs/superpowers/plans/2026-07-29-rag-v2-retrieval-ragas.md | Captures implementation plan and staged task breakdown. |
| docs/retrieval-v2-and-ragas.md | Documents retrieval modes, filters, migration, and evaluation/RAGAS usage. |
| app/api/dependencies.py | Adds commit/rollback lifecycle to session dependency and wires retrieval pipeline to Postgres store. |
| .github/workflows/rag-eval.yml | Adds CI contract checks for eval deps and an opt-in/scheduled evaluation workflow. |
| .env.example | Adds evaluation and RAGAS environment variable templates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+40
to
+45
| if options.retrieval_mode and options.retrieval_mode != "auto": | ||
| mode = options.retrieval_mode | ||
| vector_search = mode in {"vector", "hybrid"} | ||
| full_text_search = mode in {"full_text", "hybrid"} | ||
| hybrid_search = mode == "hybrid" | ||
| else: |
Comment on lines
+45
to
+50
| try: | ||
| yield session | ||
| await session.commit() | ||
| except BaseException: | ||
| await session.rollback() | ||
| raise |
Comment on lines
+76
to
+80
| DATASET="${{ inputs.dataset || 'evals/datasets/smoke.jsonl' }}" | ||
| EXTRA_ARGS="" | ||
| if [ "${{ inputs.use_ragas || 'true' }}" = "true" ]; then | ||
| EXTRA_ARGS="--ragas" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the retrieval and evaluation portion of the approved RAG V2 design:
vector,full_text,hybrid, andautoretrieval modesAPI behavior
POST /v1/retrieval/searchcontinues to support the existing boolean options and now also accepts:{"retrieval_mode": "vector | full_text | hybrid | auto"}Explicitly requested capabilities are no longer silently ignored. Invalid combinations and requests with no enabled retriever return validation errors. Responses include
effective_options, and chunks retainretrieval_methodsand per-stagescores.Migration
Apply
0004_retrieval_v2before enabling full-text or hybrid retrieval:chunks.metadatato JSONBsearch_vectorRAGAS
The optional
evaldependency group pins:ragas==0.4.3langchain-community>=0.3,<0.4to avoid the known RAGAS import incompatibility withlangchain-community0.4.xThe runner calls the real RAG API and reports deterministic Hit Rate@K, Precision@K, Recall@K, and MRR, with optional Faithfulness, Answer Relevancy, Context Precision, Context Recall, and Factual Correctness metrics.
Verification
.[dev]installation succeeded.[dev,eval]installation succeededKnown limitation
The fixed Milvus V1 schema does not contain a generic metadata JSON field. Vector metadata filtering is therefore enforced during PostgreSQL hydration after an over-fetched Milvus search. Returned results obey the filter, but very selective filters may reduce recall. True pre-ANN metadata filtering requires a future Milvus V2 collection and reindexing.
Deferred design stages
The asynchronous ingestion worker, document-version activation state machine, token-aware parser/chunker redesign, and structured citation validation are intentionally kept out of this focused PR so the retrieval contract and evaluation layer can be reviewed and deployed independently.