Skip to content
Bynarize Technologies home

AI and Automation

Retrieval-augmented generation for business documents: a practical architecture

How a RAG assistant answers questions from company documents, where it fails, and the engineering that makes it trustworthy.

By Bynarize Engineering Team. Published . 8 minute read.

?

Language models are good at writing fluent answers. Left alone, they are not good at knowing your leave policy, your product specifications or last quarter's supplier terms. Retrieval-augmented generation, usually shortened to RAG, closes that gap by finding relevant passages in your documents and asking the model to answer using only those passages.

A working demo takes an afternoon. A system people trust takes careful engineering. This article describes the architecture we use and the places where RAG systems usually go wrong.

The basic flow

A RAG system has two halves.

Ingestion, which runs when documents are added or changed:

  1. Extract text from PDFs, Word files, web pages or a document management system.
  2. Split the text into chunks small enough to retrieve precisely but large enough to keep context.
  3. Create an embedding, a numeric vector representing meaning, for each chunk.
  4. Store the chunks, embeddings and metadata such as source, section, date and access permissions.

Answering, which runs for each question:

  1. Create an embedding for the question.
  2. Retrieve the most relevant chunks, usually combining vector similarity with keyword search.
  3. Send the question and the retrieved chunks to the language model with instructions to answer only from them and to cite sources.
  4. Return the answer with links to the passages it used.

Where RAG systems fail

Poor extraction

Tables, scanned pages, headers and footers often come out of PDF extraction as noise. If the text going in is wrong, retrieval cannot find the right answer. Inspect extracted text for a sample of real documents before tuning anything else.

Chunks that lose context

A chunk that says "employees in this category are entitled to 12 days" is useless if the category was named two paragraphs earlier. Chunking by document structure, keeping headings with their content and adding the section title to each chunk improves retrieval noticeably.

Retrieval that misses exact terms

Vector search is good at meaning and weak at exact identifiers such as policy numbers, product codes and names. Hybrid retrieval, which combines vector search with keyword search, handles both.

Ignoring permissions

If an employee can ask the assistant about documents they cannot open themselves, you have built a data leak. Store access metadata with each chunk and filter retrieval by the user's permissions before anything reaches the model.

Answers without sources

An answer people cannot verify is an answer they will eventually stop trusting. Require citations, show them in the interface, and instruct the model to say it does not know when the retrieved passages do not contain the answer.

Evaluation comes first

Before building, collect fifty to a hundred real questions with the correct answers and the documents that contain them. Use this set to measure:

  • Retrieval quality: did the correct passage appear in the retrieved results?
  • Answer accuracy: was the answer correct and supported by the sources?
  • Refusal behaviour: did the system decline when the answer was not in the documents?

Run the evaluation every time you change chunking, retrieval settings, prompts or models. Without it, improvements are guesswork.

Choosing components

  • Model provider: Azure OpenAI suits organisations that want models within their Azure tenancy; the OpenAI API and other providers are alternatives. Put model access behind an internal interface so you can change providers.
  • Vector storage: for many business systems, PostgreSQL with the pgvector extension is sufficient and keeps data in a database you already operate. Azure AI Search or a dedicated vector database makes sense at larger scale or when you need built-in hybrid ranking.
  • Service layer: Python with FastAPI is a natural fit because of its ecosystem for document processing and model integration.

Keep people in the loop where it matters

For low-risk questions, such as where to find a form, an answer with a citation is enough. For decisions with consequences, such as approving an exception or quoting a contractual term, the assistant should draft and a person should confirm. Design the workflow so the AI saves time without becoming the final authority.

Operating it

After launch, track:

  • questions asked and how often users open the cited sources,
  • thumbs up and down feedback with comments,
  • latency and cost per question,
  • documents that are frequently retrieved but rated unhelpful, which usually need rewriting.

RAG is as much about content as code. The fastest improvements often come from fixing outdated or ambiguous documents that the system surfaces.

Bynarize builds RAG assistants and document intelligence on established model providers. Learn more about our AI development services and Python development.

  • RAG
  • LLM
  • Azure OpenAI
  • Vector search
  • Python

Have a business challenge or software idea?

Let's discuss your requirements and explore the right technology solution for your business.

Email
hello@bynarize.com
Phone and WhatsApp
+91 82629 95977
Response
Within one business day