Skip to content

About

Retrieval and agentic AI system for RAG: BM25, dense and hybrid search, reranking, adversarial evaluation, relevance feedback, observability, and automated Azure deployment.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Try SignalRank live

SignalRank-RAG

Reproducible retrieval, reranking, and grounded responses.

SignalRank-RAG is an open-source RAG application built with Python, FastAPI, LangGraph, and Qdrant. It combines deterministic ingestion, hybrid retrieval, optional FlashRank reranking, evidence-backed generation, and automated cloud deployment.

CI Python React / TypeScript Release Docker Qdrant Azure Cloudflare

The live Streamlit demo exposes BM25, dense, and hybrid retrieval with inspectable evidence and relevance feedback. A separate React/TypeScript Console provides a Cloudflare Pages frontend and gateway.

Experimental ACE stance classification and evidence-ledger diagnostics help evaluate whether retrieved passages contradict or qualify a proposed answer; this capability is not yet part of live answer generation.


System Architecture

AI / ML Retrieval / RAG Agentic Orchestration Platform / Software Engineering

Three views show distinct lifecycles: request processing, corpus/index preparation, and delivery/runtime. Colors indicate engineering responsibilities across all three.

1. Request processing

flowchart TB
    USER(["👤 User"])

    subgraph UX["🖥️ Interfaces"]
        direction TB
        STREAM["Streamlit demo<br/>Azure Container Apps"]
        CONSOLE["React + TypeScript Console<br/>Cloudflare Pages"]
        GATE["🛡️ Cloudflare gateway<br/>Turnstile · quota"]
        CONSOLE --> GATE
    end

    GUARD["🔐 FastAPI<br/>service token · daily quota"]
    RET["POST /retrieve"]
    CHAT["POST /chat"]
    SEARCH["🔎 SearchService<br/>BM25 · dense · hybrid/RRF<br/>optional FlashRank"]
    GRAPH["🕸️ LangGraph<br/>route · retrieve · respond"]
    LLM["✨ LLMService<br/>Groq default · OpenRouter optional"]
    QD[("🗄️ Qdrant")]
    OUT["✅ Answer or ranked evidence"]
    OBS["📈 Logfire"]

    USER --> STREAM
    USER --> CONSOLE
    STREAM -->|server-side token| GUARD
    GATE -.->|API integration| GUARD
    GUARD --> RET
    GUARD --> CHAT
    RET --> SEARCH
    CHAT -->|other requests| GRAPH
    CHAT -->|greeting shortcut| OUT
    GRAPH --> SEARCH
    GRAPH -.->|LLM calls| LLM
    QD -. semantic results .-> SEARCH
    SEARCH -->|direct retrieval| OUT
    GRAPH -->|chat response| OUT
    GRAPH -.->|LLM down: evidence only| OUT
    GUARD -. traces .-> OBS

    classDef ai fill:#665191,stroke:#A99CE8,stroke-width:1.5px,color:#ffffff
    classDef rag fill:#3F718C,stroke:#82A8CF,stroke-width:1.5px,color:#ffffff
    classDef agentic fill:#A95D45,stroke:#D6A75C,stroke-width:1.5px,color:#ffffff
    classDef platform fill:#557567,stroke:#72AA9E,stroke-width:1.5px,color:#ffffff
    classDef neutral fill:#475569,stroke:#94A3B8,stroke-width:1.5px,color:#ffffff
    class STREAM,CONSOLE,GATE,GUARD,RET,CHAT,OBS platform
    class SEARCH,QD rag
    class GRAPH agentic
    class LLM ai
    class USER,OUT neutral
Loading

/retrieve invokes SearchService directly; /chat uses LangGraph for conversation, grounded synthesis, or evidence-only responses. Both reuse the same retrieval and optional reranking pipeline. Common greetings bypass the graph.

/chat mode Behaviour
auto Structured LLM routing between conversation and retrieval
synthesis Retrieve and generate a grounded answer
evidence Return ranked evidence without LLM synthesis

Reliability: The responder abstains when evidence is insufficient. Router failures fall back to retrieval and the evidence responder; generation failures return evidence without further synthesis. Groq is the default configured provider, with OpenRouter as an alternative—not automatic cross-provider failover.

Security: /chat and /retrieve use X-SignalRank-Service-Token and share an in-process limit of 100 requests per UTC day per process (HTTP 429). The counter resets on restart; it is not distributed. /health is unauthenticated, and browser code never receives the service token.

2. Corpus and index lifecycle

flowchart TB
    DOCS["📄 Source documents<br/>PDF · Office · HTML · text"]
    HF["🤗 Hugging Face Hub<br/>all-mpnet-base-v2 model"]

    subgraph BUILD["📥 1 · Index build"]
        direction TB
        LOAD["Load + deterministic chunking"] --> EMB["🧠 Embed document chunks"]
        EMB --> QD[("🗄️ Qdrant<br/>persisted vectors + payloads")]
    end

    subgraph STARTUP["⚡ 2 · API startup"]
        direction TB
        ATTACH["Connect to existing<br/>Qdrant collection"]
        RELOAD["Reload source corpus<br/>reconstruct identical chunks"]
        MODEL["Initialize embedding model<br/>for query encoding"]
        BM["🔤 BM25<br/>in memory"]
        IDS["Chunk-ID lookup"]
        RELOAD --> BM
        RELOAD --> IDS
    end

    SEARCH["🔎 SearchService<br/>lexical · semantic · hybrid/RRF"]

    DOCS --> LOAD
    HF -.->|model weights| EMB
    QD -->|persisted index| ATTACH
    DOCS -.->|re-read at startup| RELOAD
    HF -.->|same model| MODEL
    ATTACH --> SEARCH
    BM --> SEARCH
    IDS --> SEARCH
    MODEL --> SEARCH
    QD -. semantic results .-> SEARCH

    classDef ai fill:#665191,stroke:#A99CE8,stroke-width:1.5px,color:#ffffff
    classDef rag fill:#3F718C,stroke:#82A8CF,stroke-width:1.5px,color:#ffffff
    classDef neutral fill:#475569,stroke:#94A3B8,stroke-width:1.5px,color:#ffffff
    class HF,EMB,MODEL ai
    class LOAD,QD,ATTACH,RELOAD,BM,IDS,SEARCH rag
    class DOCS neutral
Loading

Index build → API startup is the normal lifecycle: scripts/index_corpus.py stores chunk vectors in Qdrant; the API connects to that existing collection and re-reads the source corpus to rebuild BM25 and its chunk-ID lookup. Dashed arrows distinguish reused inputs from the primary flow. recreate_collection: true can instead rebuild Qdrant during startup.

The production configuration uses Hugging Face's sentence-transformers/all-mpnet-base-v2 model for both document and query embeddings (downloaded when absent from cache). Separately, SignalRank has an optional FineWiki streaming source via HuggingFaceFW/finewiki; the default production corpus is local files, not a live FineWiki dataset.

3. Delivery and runtime

flowchart TB

    subgraph BACKEND["🐍 SignalRank-RAG · Python"]
        direction TB

        SRC["GitHub · SignalRank-RAG"]
        CI["⚙️ GitHub Actions<br/>Ruff · Pyright · pytest<br/>Docker smoke test"]
        GHCR["📦 GHCR<br/>Commit-SHA image"]
        OIDC["🔑 Azure OIDC<br/>Deployment authorization"]

        subgraph AZURE["☁️ Azure Container Apps"]
            direction TB
            API["⚡ FastAPI<br/>/retrieve · /chat"]
            STREAM["🖥️ Streamlit<br/>Live demo"]
        end

        VERIFY["✅ Deployment verification<br/>Image SHA · UI reachability"]

        SRC --> CI
        CI -->|main| GHCR
        CI -->|main| OIDC

        GHCR --> API
        GHCR --> STREAM
        OIDC --> API
        OIDC --> STREAM

        STREAM -->|API requests| API
        API --> VERIFY
        STREAM --> VERIFY
    end

    subgraph FRONTEND["⚛️ SignalRank Console · React / TypeScript"]
        direction TB

        REPO["GitHub · signalrank-console"]
        PAGES["☁️ Cloudflare Pages<br/>React · TypeScript · Vite"]
        GATEWAY["🛡️ Pages Functions<br/>Turnstile · D1 quota"]

        REPO --> PAGES
        PAGES --> GATEWAY
    end

    GATEWAY -.->|HTTPS /retrieve<br/>server-side token| API

    API -.->|traces| LOG["📈 Logfire"]
    SRC -.->|manual validation| K8S["☸️ Kubernetes<br/>kind"]

    classDef platform fill:#557567,stroke:#72AA9E,stroke-width:1.5px,color:#ffffff
    classDef neutral fill:#475569,stroke:#94A3B8,stroke-width:1.5px,color:#ffffff

    class CI,GHCR,OIDC,API,STREAM,VERIFY,PAGES,GATEWAY,LOG,K8S platform
    class SRC,REPO neutral
Loading

Project Structure

SignalRank-RAG/
├── .github/workflows/       # CI/CD
├── benchmarks/retrieval/    # corpus, queries, ground truth
├── configs/                 # application and benchmark settings
├── deploy/kubernetes/       # kind-validated runtime manifests
├── scripts/                 # indexing, benchmarking, local demo
├── src/signalrank/
│   ├── agents/              # LangGraph routing and responders
│   ├── api/                 # FastAPI endpoints and request checks
│   ├── components/          # loaders, chunking, embeddings, retrieval, ranking
│   ├── config/              # typed YAML configuration
│   ├── evaluation/          # retrieval metrics
│   ├── observability/       # Logfire integration
│   ├── pipelines/           # indexing and retrieval orchestration
│   ├── services/            # search and LLM service boundaries
│   └── ui/                  # Streamlit and feedback
├── tests/
├── compose.yaml
├── Dockerfile
├── pyproject.toml
└── uv.lock

Retrieval and Reranking

  • BM25: Lexical matching for exact terms.
  • Dense: Semantic retrieval using embeddings in Qdrant.
  • Hybrid: Reciprocal rank fusion of lexical and dense rankings.
  • FlashRank: Optional second-stage reranking of retrieved candidates.

Retrieval determines the candidate set; reranking reorders it. Both are exposed through replaceable service boundaries.

Adversarial retrieval benchmark

The reproducible benchmark contains 39 documents and 30 labelled queries. Results measure first-stage retrieval, before reranking or answer generation.

SignalRank retrieval benchmark

Mode Hit@1 MRR@5
BM25 0.433 0.590
Dense 0.567 0.756
Hybrid (RRF) 0.467 0.653

Dense retrieval achieves Hit@5 = 1.000 on this corpus, but BM25 finds top-1 matches dense retrieval misses (BM25 only: 2; dense only: 6). Their top-1 oracle reaches 0.633; baseline hybrid fusion still underperforms dense retrieval. This motivates better fusion and reranking rather than assuming hybrid search must win.

Reproduce the benchmark
uv sync --extra eval
uv run --locked python scripts/index_corpus.py --config configs/benchmark.yaml --recreate
uv run --locked python scripts/benchmark_retrieval.py

The benchmark configuration pins the sentence-transformers/all-mpnet-base-v2 model, corpus, chunking, and retrieval settings. The model must be available locally or downloaded on first use.


Answer-Changing Evidence (ACE)

A RAG answer can be faithful to its visible context and still be wrong when corrective evidence was never exposed to the generator. Answer-Changing Evidence (ACE) distinguishes evidence availability from evidence exposure. The controlled research motivating this module is documented in counter-evidence-loss.

ACE metrics (controlled, oracle-labelled benchmark)

  • ACE-A — availability: 1 when the benchmark-labelled answer-changing passage exists in the corpus; otherwise 0.
  • ACE-E@k — exposure: 1 when that passage reaches the generator-visible top-k context; otherwise 0.
flowchart TB
    GOLD["Benchmark-labelled<br/>Answer-Changing Evidence"]

    GOLD --> CORPUS{"Available<br/>in corpus?"}
    GOLD --> CONTEXT{"Exposed in<br/>generator context?"}

    CORPUS --> AVAIL["ACE-A<br/>Evidence Availability"]
    CONTEXT --> EXPOSE["ACE-E@k<br/>Evidence Exposure"]

    classDef neutral fill:#475569,stroke:#94A3B8,color:#ffffff
    classDef rag fill:#3F718C,stroke:#82A8CF,color:#ffffff

    class GOLD neutral
    class CORPUS,CONTEXT,AVAIL,EXPOSE rag
Loading

Both are binary per case; benchmark summaries report their means. On the six synthetic claims in the separate research repository (k = 5):

Evidence condition ACE-A ACE-E@5 Correct answers
Exposed to generator 1.000 1.000 6/6
Available in corpus, not exposed 1.000 0.000 0/6
Absent from corpus 0.000 0.000 0/6

These oracle-labelled research metrics require knowing which passage would change the answer; they cannot be computed as ground truth for arbitrary live queries using model predictions alone.

Implemented in SignalRank-RAG: stance diagnostics

The experimental ACE component classifies candidate passages relative to a query and candidate answer as supports, contradicts, qualifies, or irrelevant. EvidenceLedger preserves passage references and counts each stance. Its answer_changing_evidence_found signal is true when at least one assessed passage contradicts or qualifies the candidate answer. This is a candidate-set diagnostic, not corpus-wide proof or an oracle ACE-A/ACE-E@k score.

flowchart TB
    INPUT["Query + Candidate Answer<br/>Retrieved Passages"]

    CLS["LLM Stance Classifier"]

    LEDGER["EvidenceLedger<br/>Passage IDs + Stance"]

    CHECK{"Contradicts<br/>or Qualifies?"}

    FLAG["Potential Answer-Changing<br/>Evidence Detected"]

    NONE["Not Detected Among<br/>Assessed Passages"]

    INPUT --> CLS
    CLS --> LEDGER
    LEDGER --> CHECK

    CHECK -->|Yes| FLAG
    CHECK -->|No| NONE

    classDef ai fill:#665191,stroke:#A99CE8,color:#ffffff
    classDef rag fill:#3F718C,stroke:#82A8CF,color:#ffffff
    classDef neutral fill:#475569,stroke:#94A3B8,color:#ffffff

    class INPUT neutral
    class CLS ai
    class LEDGER,CHECK,FLAG,NONE rag
Loading

The classifier returns structured results keyed to input chunk IDs, rejects missing or duplicate IDs, and restores the original evidence order. The offline evaluator reports stance accuracy and the rate at which safe passages (supports/irrelevant) are incorrectly flagged as answer-changing (contradicts/qualifies).

Targeted semantic validation: 17/17 annotated passages correctly classified; 5/5 answer-changing passages detected; 0/12 safe passages falsely flagged in each of three runs. This is a small, synthetic validation, not a production performance claim.

# Deterministic unit tests (no external LLM calls)
uv run pytest -q tests/test_ace_ledger.py tests/test_ace_classifier.py tests/test_ace_eval.py

# Live semantic check; requires configured LLM credentials
uv run python scripts/run_ace_semantic_eval.py

Status: The ACE ledger, classifier and evaluation tooling exist in the codebase, but ACE assessment is not yet integrated into production /chat or /retrieve decision-making. Potential future extensions includes deeper candidate-pool assessment, retrieval/exposure diagnostics, abstention calibration, and evaluation before a guarded runtime rollout. Lack of a detected contradiction is not proof that the corpus contains none.


API

Endpoint Purpose Authentication
GET /health Liveness check None
POST /retrieve BM25, dense, or hybrid results; optional reranking Service token
POST /chat Routing, grounded synthesis, or evidence-only response Service token

/chat supports auto, synthesis, and evidence response modes. The API accepts X-SignalRank-Service-Token for protected endpoints.

curl -X POST http://127.0.0.1:8000/chat \
  -H "Content-Type: application/json" \
  -H "X-SignalRank-Service-Token: signalrank-local-dev" \
  -d '{"query":"What caused the extinction of the dinosaurs?","mode":"hybrid","top_k":5}'

The example token is for local development; production credentials must be supplied through secrets.


Quick Start

docker compose up --build

For the benchmark-backed local demo on Windows:

scripts\run_demo.cmd
Development and configuration

The project uses uv with a committed lockfile.

uv sync --extra eval
uv run --locked python -m pytest -v
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked pyright

Run the services directly:

uv run uvicorn signalrank.api.main:app --reload
uv run streamlit run src/signalrank/ui/app.py

YAML configuration covers ingestion, embeddings, retrieval, fusion, reranking, Qdrant, response modes, and LLM providers. Qdrant supports in-memory, local, or remote operation. Deployment credentials come from environment variables or managed secrets, not committed configuration.

Common environment variables:

GROQ_API_KEY
GEMINI_API_KEY
OPENROUTER_API_KEY
QDRANT_URL
QDRANT_API_KEY
LOGFIRE_TOKEN
SIGNALRANK_API_URL
SIGNALRANK_SERVICE_TOKEN

Evaluation and Observability

The Streamlit UI collects Relevant / Not relevant judgements with query and result metadata for offline retrieval diagnostics. Feedback does not change rankings online.

Logfire traces API requests, retrieval, embeddings, reranking, routing, LLM calls, provider failures, and feedback events. Some evaluation logs may include submitted queries or result metadata; do not enter sensitive information into the public demo. Logfire is optional locally.


Kubernetes

Kubernetes manifests under deploy/kubernetes are validated locally with kind, including Deployment, ClusterIP Service, health probes, resource limits, HorizontalPodAutoscaler, Secrets, ConfigMaps, and Kustomize.

Azure Container Apps remains the production runtime.


Roadmap

Implemented: Deterministic ingestion; BM25, dense, and hybrid retrieval; optional FlashRank reranking; LangGraph routing, evidence-only fallback, and basic abstention; adversarial evaluation; relevance feedback; API token/quota; Azure CI/CD; Cloudflare Pages Console deployment; kind-validated Kubernetes manifests; experimental ACE stance classifier, evidence ledger, and offline evaluator.

Future directions: Reranker benchmarks and ranking diagnostics; improved fusion; stronger evidence-sufficiency and abstention calibration; larger retrieval benchmarks; retrieval-quality gates in CI; richer routing policies; ACE candidate-depth assessment and guarded runtime integration.


Cite

@software{signalrank_rag,
  author = {Bharath Sampadi},
  title = {SignalRank-RAG: Reproducible Retrieval, Reranking, and Grounded Responses},
  year = {2026},
  publisher = {GitHub},
  url = {https://github.com/bksampadi/SignalRank-RAG}
}

License

MIT License. See LICENSE.

About

Retrieval and agentic AI system for RAG: BM25, dense and hybrid search, reranking, adversarial evaluation, relevance feedback, observability, and automated Azure deployment.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages