Problem and solution
01/Problem
02/Solution
03/How it works
The system, end to end.
- 01next →
Query
User question + optional filters.
- 02next →
Retrieve
Hybrid BM25 + dense recall, top-50.
- 03next →
Rerank
Cross-encoder narrows to top-8.
- 04next →
Compose
Citation-locked prompt assembly.
- 05loop
Generate
Grounded answer + citations + score.
04/Architecture
Components and data flow.
How the moving parts fit together. Solid arrows are synchronous calls; dashed arrows are queued or batched.
- 01
Client (web/SDK)
- 02
API gateway
- 03
Query router
- 04
Hybrid retriever (BM25 + dense)
- 05
Reranker (cross-encoder)
- 06
Citation-locked LLM
- 07
Postgres + vector store
- 08
Telemetry pipeline
05/Technology
The stack.
- AI / ML
- OpenAI / Anthropic modelsBGE embeddingsCross-encoder reranker
- Frontend
- Next.jsTailwind
- Backend
- PythonFastAPILangChain
- Database
- PostgreSQLpgvectorRedis
- Infrastructure
- GitHub Actions
- APIs
- OpenAIAnthropicCohere rerank
06/Engineering decisions
What we picked, and why.
- 01
Hybrid retrieval instead of dense-only
Choice
BM25 + dense with reciprocal-rank fusion
Alternatives
- Dense-only retrieval
- Graph retrieval
Why
Lexical recall catches identifiers and rare terms that dense embeddings flatten; fusion keeps both signals honest.
- 02
Citation-locked generation
Choice
Force the model to cite, refuse when unsupported
Alternatives
- Free-form generation + post-hoc citations
Why
Locking citations into the decoding loop removed the 'confident but ungrounded' failure mode we saw in early evals.
- 03
pgvector instead of a dedicated vector DB
Choice
Postgres + pgvector
Alternatives
- Pinecone
- Weaviate
- Qdrant
Why
Customers already ran Postgres. One fewer system to operate, transactional consistency for free.
07/Evaluation
What we measured.
- 01
94%
Grounded
- 02
91%
Citation precision
- 03
1.4s
p95 latency
- 04
6%
Refusal rate
08/Challenges
What almost broke us.
- 01
Long-document retrieval drift
What happened
Answers slowly drifted as corpus grew.
What we did
Introduced per-chunk metadata anchors + cross-encoder reranker.
- 02
Citation hallucination
What happened
Model cited plausible-but-wrong passages.
What we did
Switched to citation-locked decoding and required refusal when no support.
09/Results
Reduced ungrounded answers from ~22% to ~6% on the internal eval set. Three enterprise teams moved from pilot to production within a quarter.
10/Future improvements
- ›Multimodal retrieval over diagrams and tables
- ›Streaming answers with progressive citations
- ›Tenant-aware evals as a managed service
Have an interesting AI problem?
Let's build something.
If you're working on something that needs real AI engineering — not just a demo — let's talk.