lexicon
Grounded document Q&A that gives cited answers or refuses.
GitHub repo (opens in a new tab) ↗Changelog (opens in a new tab)
- License:
- AGPL-3.0
- CI security:
- CodeQL, gitleaks, npm audit, osv-scanner, pip-audit
~/problem
Document Q&A that sounds confident but is wrong is costly. A feasibility spike showed similarity scores could not separate a correct answer from a topically adjacent wrong one, so refusal is enforced by a separate verification step.
A FastAPI and Next.js system that answers questions only when the answer is backed by citations in the supplied documents. An independent groundedness verification call, not a similarity threshold, decides between answering and refusing. v1.0.0 is tagged.
~/highlights
- Hybrid retrieval over PostgreSQL with pgvector; retrieval recall@k is measured for real (9/9) because it never calls an LLM.
- Verification call hardened against prompt injection inside passages: 18 of 18 structural containment across an 18-document adversarial corpus.
- Tamper-evident audit trail (ADR-0002) and instance-level authentication (ADR-0005).
- Committed, CI-gated evaluation harness with a golden dataset.
- Production-shaped compose stack with non-root images and a pre-warmed embedding model; three bugs found and fixed by running it.
- No LLM API key exists in the project by design (ADR-0004): all quality numbers measure the harness against a deterministic stub, and the README says so.
~/decisions
From the repo's own decision log, not summarized from memory.
Refusal is enforced by a second LLM call, not a similarity threshold
A feasibility spike measured that retrieval similarity alone can't separate "topically close but wrong" from "actually correct" (0.701 for a wrong answer, inside the 0.706–0.848 range of correct ones). The system now generates an answer with mandatory citations, then runs an independent verification call against the cited passages, and only returns the answer if every claim verifies.
~/architecture
- Next.js frontend → FastAPI backend
- Sign in, corpora, upload and question form.
- FastAPI backend → PostgreSQL + pgvector, Redis, MinIO, LLM client
- Ingestion, hybrid retrieval, generation, verification, audit trail.
- PostgreSQL + pgvector
- Chunks, embeddings, corpora, audit records.
- Redis
- Supporting store used by the backend.
- MinIO
- S3-compatible document storage.
- LLM client
- StubLLMClient by default; Anthropic client when a key is configured.
~/stack
- Python 3.12
- FastAPI
- Next.js 16
- PostgreSQL
- pgvector
- Redis
- MinIO
- Docker
~/status
v1.0.0 tagged, AGPL-3.0. Real LLM verification is permanently descoped, so answer quality has not been measured against a real model.
~/related
- lexicon-android Android client for lexicon with offline caching and background sync.