Skip to content
Svayam Labs
Engineering notes

Building an AI intelligence engine experts will trust

Citation-enforced RAG, hybrid retrieval and local inference — how we make an LLM useful in a high-stakes domain without letting it bluff.

12 May 2026 2 min read
  • AI engine
  • RAG
  • Retrieval
  • Guardrails

In knowledge-heavy domains, a fluent-but-wrong assistant is worse than none — one confident hallucination and the experts stop trusting it for good. So our default intelligence engine inverts the usual order: it must ground a claim before it may make one.

The pipeline

  1. Query

    user question + filters

  2. Hybrid retrieve

    BM25 + pgvector

  3. Rerank

    cross-encoder, top-k

  4. Assemble

    context + source IDs

  5. Generate

    grounded, source-tagged

  6. Citation check

    every claim → a source

  7. Answer · or refuse

    blank beats a guess

The runtime path of a single question

How it works

Hybrid retrieval. Pure vector search misses exact terms (a section number, a chemical name); pure keyword search misses meaning. We run both — BM25 over a full-text index and ANN over pgvector embeddings — and fuse the results, then rerank with a cross-encoder so the top of the context window is the most relevant material, not just the most similar.

Citation enforcement. Generation is constrained to cite, and a verification pass checks that each asserted claim maps back to a retrieved chunk. If a sentence can’t be grounded, it doesn’t ship — the engine returns “I don’t have a source for that” instead. The failure mode becomes a blank, never a fabrication.

Local by default. The corpus and the model run on the client’s own hardware. Nothing — not the documents, not the prompts — leaves the network.

How it was built

  • Vectors & search: PostgreSQL + pgvector, with the same database carrying full-text (BM25) so retrieval is one datastore, not three.
  • Embeddings: a multilingual embedding model served locally, so Indian-language corpora retrieve as well as English ones.
  • Generation: a mid-size open model run in a grounded, low-temperature mode.
  • Evaluation: a golden set of question/answer/source triples, scored on citation coverage (share of claims with a valid source) and refusal correctness (does it decline when it should?). We treat a regression in either as a build failure, not a nuance.

The result is an engine whose answers are checkable — which, in the domains we work in, is the only kind anyone will actually use.


Building something like this?

We'd rather talk specifics than slogans. Tell us what you're trying to build.

Talk to us