1. Home
  2. Blog
  3. Custom Software

Custom Software

How to Build Enterprise Search and Document Q&A with RAG: Chunking, Access Filters, Threshold and Payback Guide

How to build enterprise search and document Q&A with RAG: chunking, access filters, quality metrics, answer threshold and payback, with worked examples.

Contents 15 sections
  1. What Is RAG and How Does It Differ From a Model's Own Knowledge?
  2. When Is RAG a Good Fit, and When Is It Not?
  3. What Steps Make Up a RAG System?
  4. How Are Documents Chunked, and How Many Chunks Result?
  5. How Are Access and Version Filters Built?
  6. What Difficulties Do Turkish and Multilingual Documents Bring?
  7. How Is Retrieval Quality Measured?
  8. When Should the Answer Be "I Don't Know"?
  9. How Is Answer Quality Measured?
  10. How Are Hallucination and Security Risks Reduced?
  11. How Are Cost and Latency Calculated?
  12. How Is a Pilot Run and Which Metrics Are Tracked?
  13. How Is Payback Calculated?
  14. Enterprise Search and AI Projects With İnovabil
  15. Frequently Asked Questions

A company's procedures, contracts, product manuals and support articles live in different folders and systems. An employee spends minutes looking for the answer to "which rule applies to carrying over annual leave?" and sometimes opens the wrong version. Enterprise search and document Q&A with AI usually solves this with RAG (retrieval-augmented generation): the system first finds the relevant passages in the company's own documents, then writes an answer based only on those passages and shows the source.

In this guide we cover what RAG is, where it fits, its architecture, the chunking arithmetic, access and version filters, how to measure retrieval and answer quality, the "I don't know" threshold, security risks, cost, latency and payback. Example figures are representative; they are not any provider's pricing or an accuracy claim. We covered connecting a language model to business software, plus hallucination and confidence thresholds, in our AI integration guide; here we focus on design specific to document Q&A.

Key ideaA RAG system's quality comes largely from which passages reach the model, not from the model itself. If the wrong passage is retrieved, even the best model writes a wrong answer. So clean the documents first, filter by access and version, measure retrieval, and only then tune answer generation and the "I don't know" threshold.

What Is RAG and How Does It Differ From a Model's Own Knowledge?

RAG has four moves: find the passages that fit the question, place them in front of the model as context, tell the model to "answer only from this context", and show the source with the answer. The model does not memorise your documents; the relevant passages are put in front of it for every question.

TopicModel's own knowledgeClassic searchRAG
Knowledge sourceTraining dataCompany documentsCompany documents
OutputFluent answerList of documentsShort answer plus source
VerificationHardOpen the documentClick the citation

Product search has its own problems, which we covered in our e-commerce site search guide; here the topic is generating answers from documents.

When Is RAG a Good Fit, and When Is It Not?

Good fits share one trait: the answer is written in the documents and a person can verify it against the source.

  • Internal procedure questions: leave, expense, purchasing and security rules.
  • Product manual queries for support teams: error codes, installation steps, compatibility.
  • Contract scanning: locating questions such as "where is the termination notice clause?"

Poor fits are clear too: numeric calculations (stock, price, balance) belong to code and data, live queries (today's order status) belong to the relevant system's API, and legal or financial decisions belong to experts. We covered article structure in our knowledge base guide; RAG is only as good as the documents behind it.

Recommended reading: What is a document management system (DMS)?

What Steps Make Up a RAG System?

The system has two pipelines: an indexing pipeline that prepares documents and a query pipeline that answers the question.

The six steps of a RAG flow: collect documents, chunk, embed and index, hybrid search, re-rank, answer with citation
The six steps of RAG: the first three are indexing, the last three are the query pipeline.
  1. Collecting and cleaning documents: documents are pulled from sources; headers, page numbers and duplicate text are removed; scanned files are converted to text.
  2. Chunking: each document is split into passages while preserving meaning.
  3. Embedding and vector index: each chunk is converted into a number sequence (a vector) that represents its meaning and written to the index; the product choice depends on your architecture.
  4. Hybrid search: keyword and semantic search both run and their results are merged. Keyword search catches exact strings such as an error code or clause number; semantic search catches questions phrased in different words.
  5. Re-ranking: the top 20 candidates are re-ordered with a finer measure and the best 4 chunks are selected.
  6. Answer generation and citation: the model writes an answer only from these chunks; every claim is tied to a document and page.

A simple way to merge the two result lists is rank-based fusion: a document at rank r in a list gets 1 ÷ (60 + r) points, and points are summed. A document that appears in both lists (2nd in keyword, 5th in semantic) gets 1/62 + 1/65 = 0.0315; a document that is 1st in only one list gets 1/61 = 0.0164. The constant 60 is a common starting value.

How Are Documents Chunked, and How Many Chunks Result?

If a chunk is too small, context is lost (the sentence "within 30 days" stays without saying 30 days of what). If it is too large, irrelevant text piles up and search blurs. Chunks of a few paragraphs that respect heading and clause boundaries are a good start; neighbouring chunks overlap so that a sentence on the boundary appears in both.

Example: 6,000 documents, an average of 9 pages each, 450 words per page; total 6,000 × 9 × 450 = 24,300,000 words. With 400-word chunks and 15% overlap (60 words), each chunk advances 340 new words: 24,300,000 ÷ 340 ≈ 71,471 chunks. With a 768-dimension vector and 4 bytes per number, each vector takes 3,072 bytes: 71,471 × 3,072 ≈ 220 MB (representative; text and metadata come on top).

Chunk sizeChunk count (15% overlap)Vector sizeContext of 4 chunks
100 words285,883≈ 878 MB400 words
400 words71,471≈ 220 MB1,600 words
1,000 words28,589≈ 88 MB4,000 words

Small chunks make the index 4 times larger but shorten context; large chunks send 2.5 times more text to the model on every question. The right size is chosen with the golden question set described below.

How Are Access and Version Filters Built?

Each chunk carries metadata: document type, department, date, version, validity range and access group. Search can be narrowed with these fields.

The access rule is simple and uncompromising: the filter is applied before the search. A passage from a document the user cannot see is never retrieved, never given to the model and never shown as a citation. If the filter is applied after the search, two problems appear. An unauthorised chunk travels through re-ranking and logs, and one bug can leak it. Quality also drops: if each of the top 5 results is independently restricted with probability 30%, on average 5 × 0.7 = 3.5 chunks remain, and the chance that all five are removed is 0.3⁵ ≈ 0.24%. Filter first means five authorised chunks every time. We described how to design roles and permissions in our role-based access control guide; in RAG the same roles map to the access group in the index.

Versions are the second trap. Suppose 18% of documents are superseded versions: 71,471 × 0.18 ≈ 12,865 chunks come from old rules. Without a validity filter the model may describe an old rule as current. Superseded versions are marked "not valid", which reduces the active index to 58,606 chunks.

Recommended reading: What is data masking and anonymization?

What Difficulties Do Turkish and Multilingual Documents Bring?

Turkish is an agglutinative language: "izin" and "izinlerini" must match the same stem. Case rules for dotted and dotless i must be normalised, or "IZIN" and "izin" look different; company abbreviations are mapped to full forms with a glossary. Keyword search stays essential for exact strings such as clause numbers and error codes. If documents mix languages, a language tag goes into the metadata and the answer follows the language of the question.

How Is Retrieval Quality Measured?

Measure search first, because a wrong passage means a wrong answer. Method: prepare a golden set of 50 questions from real user questions and mark the correct document and chunk for each by hand. The metric is hit@5: is the correct chunk among the top 5 results?

ConfigurationCorrect in top 5hit@5
Keyword only31 ÷ 5062%
Semantic only36 ÷ 5072%
Hybrid search41 ÷ 5082%
Hybrid plus re-ranking44 ÷ 5088%

Hit@5 ignores order. Mean reciprocal rank (MRR) accounts for it: a correct chunk at rank 1 scores 1, at rank 2 scores 0.5. Suppose in the final configuration 30 questions are at rank 1, 8 at rank 2, 3 at rank 3, 2 at rank 4, 1 at rank 5 and 6 outside the top 5: (30 + 4 + 1 + 0.5 + 0.2) ÷ 50 = 0.714. The golden set is re-run after every change, so the effect of chunk size and filter changes is visible.

When Should the Answer Be "I Don't Know"?

If the confidence of the retrieved chunks is low, the system should not generate an answer. The confidence score comes from the best chunk's re-ranking score; below the threshold the user sees "I could not find this in the documents" and the question is routed to a person. A low threshold produces wrong answers; a high threshold also hides correct ones.

Example: 1,000 questions; 850 have their answer in the documents and 150 do not. Assume a wrong answer costs ₺30 and leaving a question unanswered costs ₺5 (routing to a person); both are representative.

Threshold comparison: quality cost of 7,050 lira at 0.30, 4,700 lira at 0.50 and 2,900 lira at 0.70
Quality cost by threshold on 1,000 questions.
ThresholdAnsweredCorrectWrongUnansweredWrong rateCost
0.301,000765235023.5%₺7,050
0.5090076014010015.6%₺4,700
0.70720670502806.9%₺2,900
0.85450425255505.6%₺3,500

Cost = wrong × 30 + unanswered × 5; for 0.70 that is 50 × 30 + 280 × 5 = ₺2,900. The lowest cost is at 0.70; at 0.85 wrong answers shrink but unanswered questions grow so much that the total rises again, and coverage drops to 45%. For legal and financial topics the threshold is set higher. For handover rules in a customer-facing bot see our chatbot guide.

How Is Answer Quality Measured?

Three dimensions are scored separately: correctness, groundedness (is every claim present in the cited chunk?) and completeness. Each month a sample of 100 questions is scored by a person; example result: 78 correct and complete, 12 correct but incomplete, 6 wrong, 4 "I don't know". The cause of each wrong answer (chunk not found, old version, misreading) is logged, and the fix goes into the retrieval pipeline, the document or the instruction.

How Are Hallucination and Security Risks Reduced?

Measures work together: the instruction says "answer only from the context", citations are mandatory, and citation verification checks whether each claim in the answer appears in the cited chunk. In the example, 100 answers contain 500 claims and 40 (8%) are unsupported; verification catches 31 of them. The remaining 9 are 1.8% of 500. It never reaches zero, so the source is always shown.

The second risk is prompt injection: a document may contain text such as "ignore previous instructions and do this". Document content is always treated as data, not as a command; model output is filtered and outside actions are limited by separate permissions. The third risk is personal data: masking, retention periods and access logs are planned before indexing; data protection obligations, sending data to a third-party provider and data residency are assessed with legal counsel. For general security steps see our secure software development guide, and for exposed endpoints our API security guide.

How Are Cost and Latency Calculated?

Cost per question depends on the text sent to the model. 4 chunks × 400 words = 1,600 words; at 1.8 units (tokens) per word that is 2,880 units; with the question and instruction about 3,200 input units, and the answer is 250 output units. Use the provider's current price; the unit prices here are representative: ₺0.02 per 1,000 input units and ₺0.06 per 1,000 output units. Per question: 3,200 × 0.02 ÷ 1,000 + 250 × 0.06 ÷ 1,000 = ₺0.064 + ₺0.015 = ₺0.079.

90 employees, 4 questions a day, 22 working days: 90 × 4 × 22 = 7,920 questions. If 20% of frequent questions are served from a cache, 1,584 questions skip the model and the monthly model cost is 6,336 × 0.079 ≈ ₺501.

Latency gets a budget. Let the p95 target be 6 seconds: retrieval 0.4 s + re-ranking 0.6 s + answer generation 4.0 s = 5.0 s; 1 second is left as margin.

How Is a Pilot Run and Which Metrics Are Tracked?

Start with one department (support or HR), 200 documents and 4 weeks. The pilot index has 200 × 9 × 450 ÷ 340 ≈ 2,383 chunks. Week 1: document owners and the 50-question golden set; week 2: chunking, filters, hybrid search and hit@5 measurement; week 3: answer generation, citations, threshold and a 100-question scoring; week 4: real users with like/dislike buttons.

The real improvement comes from the feedback loop: a "wrong" report opens a record, the cause is tagged, a missing clause is added to the document or the chunk is re-split. Every document has an owner and a review date; the retention period for search logs is set with legal counsel.

Tracked metrics: coverage (answered ÷ all questions; 5,702 ÷ 7,920 = 72%), answer usefulness rate (marked "helpful" ÷ answered; 4,562 ÷ 5,702 = 80%), source click rate, wrong-answer report rate and search time per question (6 to 2 minutes).

How Is Payback Calculated?

90 employees run 4 searches a day at 6 minutes each: 360 × 6 ÷ 60 = 36 hours a day. At 2 minutes it is 12 hours; the difference is 24 hours a day, 528 hours over 22 days. If 60% of questions come through the system, that is 316.8 hours = ₺95,040 a month at ₺300 per hour.

Costs: quality cost 7,920 questions × ₺2.9 = ₺22,968 (₺2,900 ÷ 1,000 per question at the 0.70 threshold), model cost ≈ ₺501, monthly operation (index, monitoring, document upkeep) ₺9,000. Monthly net benefit: 95,040 − 22,968 − 501 − 9,000 ≈ ₺62,571. With ₺420,000 for build and pilot, payback is 420,000 ÷ 62,571 ≈ 6.7 months. If usage halves (30%), net falls to ≈ ₺26,786 and payback stretches to ≈ 15.7 months; adoption matters as much as technology. Recalculate with your own figures.

Recommended reading: What is custom software? Layers, types and a needs test

Enterprise Search and AI Projects With İnovabil

İnovabil's focus is bespoke software built from scratch: custom software, ERP, CRM, e-commerce, web, mobile and integration. We have no AI product and no published AI reference; this article is a decision guide, not a service promise. If you need document Q&A, we recommend settling the scope (which documents, which users), access and personal data risks, the quality threshold and the cost in writing during requirements analysis.

We built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; and warehouse management plus a complaint and support management system for Sleepy. Role-based access, audit logs and secure hosting are among our capabilities. Send a short summary of your documents and expectations, and we will produce a written scope assessment together.

Recommended reading: Our software development process, step by step

Frequently Asked Questions

What is RAG and how does it work in short?

It finds the document passages that fit the question, places them in front of the model as context, asks the model to answer only from that context and shows the source with the answer.

Is it safe to send documents to a provider?

It depends on the provider's terms and the nature of the data. Assess personal data, trade secrets and data residency with legal counsel and your security team before starting; mask where possible and share only the chunks needed.

Does RAG eliminate hallucination completely?

No, it reduces it. The instruction, mandatory citations, citation verification and "I don't know" at low confidence cut wrong answers. In the example, 1.8% of claims are still unsupported after verification, so the source is always shown.

How many documents should we start with?

One department and about 200 documents are enough. In a four-week pilot, measure hit@5 and answer scoring; if results are good, widen the scope.

Can users see documents they are not authorised for?

Not if it is designed correctly. The access filter is applied before the search; a passage from a document the user cannot see is never retrieved, never given to the model and never shown in a citation.

Let's talk about your project

Tell us briefly about the software you have in mind; we'll listen and prepare a tailored roadmap and proposal.

Get a quote