LLM engineering

LLM and RAG Engineering for Production Systems

We design, review and harden LLM applications and retrieval-augmented generation pipelines, with eval sets, retrieval metrics and latency budgets that make quality measurable.

The problem

Why RAG quality is inconsistent

Most RAG failures are retrieval failures that look like model failures. The right passage was never indexed, was split across chunks, lost to a better-scoring but irrelevant neighbor, or arrived alongside so much noise that the model ignored it. Without separate metrics for retrieval and generation, teams tune prompts to compensate for a search problem and the system stays unpredictable.

Signals you’ll recognize

  • Answers are correct in demos and wrong for real users, and nobody can explain why.
  • The team changes prompts or models to fix issues that come from chunking, metadata or ranking.
  • There is no labeled set of questions with known source documents to test against.
  • Answers cite the wrong document, an outdated version, or nothing at all.
  • Latency is acceptable at p50 but p95 is too slow for the product.
  • Access control on source documents is not enforced at retrieval time.

Retrieval-augmented generation is simple to demo and hard to keep reliable. Quality depends on dozens of small decisions, from how PDFs are parsed to how many chunks are passed to the model, and each one interacts with latency and cost.

We treat an LLM application as a system with measurable stages. Retrieval gets its own metrics, generation gets its own metrics, and both are scored against a golden dataset built from real questions. That separation is what lets a team stop guessing which change fixed or broke something.

Engagements range from a focused review of an existing pipeline to building a new retrieval and generation path with your team. In both cases the output includes the eval harness and tracing, so quality stays measurable after we leave.

What’s included

System design review

We map the request path end to end: ingestion, parsing, chunking, embedding, indexing, retrieval, reranking, prompt assembly, generation, post-processing and logging.

Retrieval engineering

We test chunking strategies, metadata filters, hybrid lexical and vector search, query rewriting and reranking, scored with recall@k and precision on a labeled query set.

Grounded generation

We design prompts and output schemas that require citations, handle no-answer cases explicitly and keep the model inside the retrieved evidence.

Evaluation harness

We build a golden dataset of questions, expected sources and reference answers, and separate retrieval metrics from answer metrics so failures can be localized.

Latency and cost budgets

We set p50 and p95 budgets per stage, and tune context size, reranker depth, streaming and caching to stay within them.

Permissions and data handling

We check that document-level access controls are enforced at retrieval time, and that sensitive fields are handled according to your policies before they reach a model.

What’s not included

  • Building or hosting a general-purpose search product or a proprietary vector database.
  • Content creation or curation of your knowledge base beyond what is needed for evaluation.
  • Ongoing 24/7 operation of the system after handoff, unless separately scoped.

How the engagement runs

Read our approach
  1. Step 1

    Map the system and failure modes

    Trace real requests end to end and categorize failures: missing content, bad retrieval, bad ranking, ignored context, formatting, or refusal.

  2. Step 2

    Build the eval set

    Assemble questions from real usage with expected source documents and reference answers, including no-answer and adversarial cases.

  3. Step 3

    Fix retrieval first

    Iterate on parsing, chunking, metadata, hybrid search and reranking, measuring recall@k and precision before touching prompts.

  4. Step 4

    Tune generation and budgets

    Adjust prompt structure, citation requirements, context size and model choice, scored on groundedness, correctness and latency.

  5. Step 5

    Gate releases

    Wire the eval set into CI as a regression gate and add production tracing so drift and new failure types show up quickly.

What we measure

Scoped engagement: deliverables, timeline and price are agreed in writing before work starts.

Retrieval recall@k
Share of labeled questions where at least one expected source passage appears in the top k results.
Answer correctness
Share of golden dataset answers judged correct against reference answers, using rubric-based model grading calibrated on a human-labeled subset.
Groundedness and citation accuracy
Share of answer claims supported by the cited passages, checked by rubric grading and spot-checked by humans.
No-answer precision
On questions the corpus cannot answer, the share where the system correctly declines instead of guessing.
p50 and p95 end-to-end latency
Measured from traces per stage (retrieval, rerank, generation) to locate the slowest component.
Cost per successful answer
Total retrieval, reranking and generation cost divided by answers that pass the correctness criteria.

Examples

Hypothetical example

Policy assistant citing outdated documents

An internal assistant answers HR and policy questions but sometimes cites superseded versions. The review finds that old and new documents are indexed together without effective-date metadata. Adding version metadata, filtering at retrieval time and testing against a labeled set of policy questions makes the failure measurable and testable before release.

Hypothetical example

Technical docs search with high p95 latency

A developer-docs assistant retrieves 50 chunks and reranks all of them with a large cross-encoder, which pushes p95 latency past the product target. The team compares reranker depth of 50, 20 and 10 on the eval set to find where recall@k stops improving, then sets the depth and latency budget from that evidence.

What you receive

Architecture and failure analysis

A diagram of the current pipeline with categorized failure modes and their measured frequency on the eval set.

Golden dataset and eval harness

Labeled queries, expected sources and reference answers, with scripts your team can run locally or in CI.

Retrieval and generation recommendations

Tested changes with before-and-after metrics, tradeoffs and implementation notes.

Latency and cost budget

Per-stage p50/p95 targets and the configuration that meets them.

Production observability plan

What to trace and log per request so regressions and new failure modes are visible.

When this isn’t the right fit

We’d rather tell you before we start.

  • Use cases where the full knowledge base fits comfortably in the model context and changes rarely; long context with prompt caching may be simpler.
  • Teams without access to the source documents or a way to label expected answers.
  • Projects that only need a quick prototype with no plan to run in production.

Common questions

Should we use RAG or fine-tune a model?

For knowledge that changes or must be cited, retrieval is usually the starting point. Fine-tuning tends to help with format, style or narrow task behavior rather than adding facts. We decide with an eval set, not by default.

Which vector database or embedding model do you recommend?

It depends on your scale, filters, latency target and existing stack. We compare a small set of options on your labeled queries and pick based on recall, latency, cost and operational fit.

Can you work with our existing framework?

Yes. We work with the stack you already run, whether that is a framework or custom code, and recommend changes only where they affect measured quality, latency or maintainability.

How large does the eval set need to be?

Large enough to cover your main query types and known failure modes with more than a handful of examples each. We usually start small, grow it from production failures, and track it under version control.

How do you handle documents with access restrictions?

Permissions should be enforced at retrieval time using document metadata, not left to the model. We review how ACLs flow from the source system into the index and test for leakage.

Talk to an AI Engineer

We walk through your current pipeline and failure examples, and outline what an assessment or build engagement would cover.