Agentic RAG context layer

Custom MCP servers and a context layer that halved token use and kept hallucinations below 2%.

Organisation
Xylont
Role
Technical Manager — design and architecture
Period
2026
Status
In production
Fig. 03: Agentic RAG context layer — simplified architectureIn production
  1. Query
  2. Semantic cacheHit → cached response
  3. Agentic retrievalCustom MCP servers
  4. PostgreSQL + pgvector
  5. LLM
  6. Grounded response
Simplified query path. Questions close to ones already answered return from the cache.

In brief

Every AI answer costs money, takes time and can be wrong. I designed the layer that decides what context a model sees for clinical and financial questions — and recognises questions it has already answered. Token use halved, slow answers take 42% less time, and hallucination rates stay below 2%.

For engineers

Custom MCP servers and an agentic RAG context-management layer over PostgreSQL with pgvector, fronted by a semantic cache. Token consumption −50%, P95 query latency −42%, hallucination rate under 2% across clinical and financial queries.

  • MCP
  • Agentic RAG
  • PostgreSQL
  • pgvector
  • Semantic caching

Context

Xylont’s AI products answer clinical and financial questions — domains where an answer has to be right, fast and affordable at the same time.

Problem

Without careful context management, every query sends a model more than it needs. Token costs rise, latency grows, and irrelevant or missing context invites hallucination.

Approach

Custom MCP servers expose tools and data to agents through a single protocol.

An agentic retrieval layer decides, per query, what context to assemble from PostgreSQL with pgvector.

A semantic cache sits in front, returning cached responses to questions close to ones already answered.

Architecture

The components in Fig. 03, in the order a request moves through them:

Query
Input
Semantic cache
Data · Hit → cached response
Agentic retrieval
Agents · Custom MCP servers
PostgreSQL + pgvector
Data
LLM
Model
Grounded response
Output

Stack: MCP · Agentic RAG · PostgreSQL · pgvector · Semantic caching

Key decisions

  1. MCP as the integration layer

    One protocol between agents and every tool or data source, instead of bespoke glue for each.

  2. Retrieval inside PostgreSQL

    pgvector keeps embeddings alongside the rest of the data in PostgreSQL.

  3. Cache by meaning

    Semantic caching matches questions by meaning rather than exact wording, so repeat questions skip the expensive path.

Outcome

  • 50%

    lower LLM token consumption

  • 42%

    lower P95 query latency

  • <2%

    hallucination rate across clinical and financial queries

LLM token consumption, indexed

Before
100
After
50

Half the tokens for the same questions

Start a conversation

Have a difficult problem,
interesting market,
or ambitious idea?

Let’s explore whether there’s something worth building together.