AGENCYSCRIPT
CoursesEnterpriseBlog
đź‘‘FoundersSign inJoin Waitlist
AGENCYSCRIPT

Governed Certification Framework

The operating system for AI-enabled agency building. Certify judgment under constraint. Standards over scale. Governance over shortcuts.

Stay informed

Governance updates, certification insights, and industry standards.

Products

  • Platform
  • Certification
  • Launch Program
  • Vault
  • The Book

Certification

  • Foundation (AS-F)
  • Operator (AS-O)
  • Architect (AS-A)
  • Principal (AS-P)

Resources

  • Blog
  • Verify Credential
  • Enterprise
  • Partners
  • Pricing

Company

  • About
  • Contact
  • Careers
  • Press
© 2026 Agency Script, Inc.·
Privacy PolicyTerms of ServiceCertification AgreementSecurity

Standards over scale. Judgment over volume. Governance over shortcuts.

On This Page

Step 1: Gather and Clean Your DocumentsStep 2: Chunk the TextA quick sanity checkStep 3: Generate EmbeddingsStep 4: Load Into a Vector StoreStep 5: Build the Retrieval StepAdd hybrid search earlyStep 6: Assemble the Prompt and GenerateStep 7: Build a Tiny Evaluation SetStep 8: Tune the Weak StageFrequently Asked QuestionsHow long does a first working version take?What chunk size should I actually use?Do I need a reranker in version one?How do I handle documents that change often?What if retrieval returns nothing relevant?Key Takeaways
Home/Blog/Go From an Empty Repo to Grounded Answers Today
General

Go From an Empty Repo to Grounded Answers Today

A

Agency Script Editorial

Editorial Team

·October 27, 2025·8 min read
retrieval augmented generationretrieval augmented generation how toretrieval augmented generation guideai fundamentals

You can read about retrieval augmented generation for a week and still not have one running. This guide is the opposite of that. It is a concrete sequence you can follow today to go from an empty project to a system that answers questions grounded in your own documents. Do each step in order, verify it works before moving on, and you will have a real pipeline by the end.

I am going to assume you have a set of documents you want to query and access to an embedding model and a language model through an API. Everything else, we will build. Where a decision has real trade-offs, I will tell you the default to pick and why, so you are not stuck weighing options you do not yet have the experience to judge.

If you want the conceptual background first, the complete guide covers the architecture. This page is for building.

Step 1: Gather and Clean Your Documents

Start by collecting the source material into one place. Whatever format they live in, convert them to plain text or markdown. PDFs are the usual headache: extract the text and check that tables and multi-column layouts did not scramble into nonsense, because garbled text in equals garbled answers out.

Strip boilerplate that repeats on every page, like headers, footers, and navigation. These pollute embeddings and waste retrieval slots. Spend real time here. Every later step inherits the quality of this one, and no clever retrieval recovers from documents that were mangled during extraction.

Step 2: Chunk the Text

Split each document into chunks. Your default: 500 tokens per chunk with about 50 tokens of overlap between consecutive chunks. The overlap keeps a sentence that straddles a boundary intact in at least one chunk.

Do not split blindly on character counts if you can avoid it. Split on natural boundaries first, headings, paragraphs, list items, and only fall back to fixed sizes within those. A chunk that respects document structure carries more coherent meaning, which makes its embedding more useful.

A quick sanity check

Read ten random chunks. Each one should make sense on its own, the way a paragraph pulled from a book still reads as a complete thought. If your chunks are fragments or sprawling walls of mixed topics, fix chunking now before you embed anything.

Step 3: Generate Embeddings

Run every chunk through your embedding model to get a vector for each. Pick one embedding model and commit to it, because the model you use to index must be the same one you use to query. Batch the requests to stay within rate limits and to keep costs down.

Store the original chunk text alongside its vector and a metadata record: source document, section heading, and any tags like product line or date. You will need that metadata for filtering and for showing citations later, and adding it after the fact means re-indexing everything.

Step 4: Load Into a Vector Store

Put the vectors and their metadata into a vector store. For a first build, do not over-engineer this. A vector-enabled relational database like Postgres with pgvector handles up to a few hundred thousand chunks comfortably and keeps your data in one familiar system.

Verify the load with a manual query: embed a test question, search, and print the top five chunks. Read them. If a question whose answer you know returns the right chunk near the top, your indexing works. If it does not, the bug is in steps 2 through 4, and you want to catch it now rather than after wiring up the model.

Step 5: Build the Retrieval Step

Write the function that turns a question into chunks. It embeds the question with the same model, searches for the nearest vectors, and returns the top-k chunks. Start with k equal to 5.

Add hybrid search early

Pure vector search misses exact strings like error codes, SKUs, and proper names. Add a keyword search over the same chunks and combine the two result lists. This one addition prevents a whole category of frustrating misses and is worth doing before you ship anything. The best practices guide explains why hybrid retrieval consistently beats pure vector search.

Step 6: Assemble the Prompt and Generate

Now connect retrieval to the model. Build a prompt with three parts: an instruction, the retrieved chunks, and the user's question. The instruction is where you control behavior, so be explicit:

  • Tell the model to answer using only the provided context.
  • Tell it to say it does not know when the context lacks the answer.
  • Tell it to cite which chunk each claim came from.

Send that prompt to the language model and return its answer plus the source chunks so users can verify. That verification path matters more than it sounds; it turns a black box into something a user can trust and correct.

Step 7: Build a Tiny Evaluation Set

Before you tune anything, create twenty to fifty question-and-answer pairs where you also note which source document contains the answer. This is your ground truth.

With it, you can measure two things every time you change something. Did retrieval surface the correct source chunk, and did the final answer match the expected answer? Without this set you are guessing, and every tweak becomes a matter of opinion. With it, you can prove a change helped or hurt. The checklist includes this as a non-negotiable gate before launch.

Step 8: Tune the Weak Stage

Run your eval set and look at the failures. Diagnose each one as retrieval or generation.

If the right chunk was never retrieved, work on retrieval: adjust chunk size, raise k, strengthen hybrid search, or add a reranker that reorders the top candidates. If the right chunk was retrieved but the answer was still wrong, work on the prompt or the context assembly. Fix the stage the data points to, re-run the eval, and repeat. This loop, measure then fix the proven weak point, is the entire discipline of improving a RAG system. For the failure patterns to watch for, see the common mistakes.

Frequently Asked Questions

How long does a first working version take?

A focused engineer can get a basic pipeline answering questions in a day or two. Steps 1 through 6 are the build; steps 7 and 8 are the ongoing work that turns a demo into something trustworthy. Do not skip the evaluation steps even when the demo looks impressive.

What chunk size should I actually use?

Start at 500 tokens with 50 token overlap and adjust based on your evaluation results. Dense reference material often wants smaller chunks for precision; narrative or procedural content often wants larger chunks to preserve flow. Let your eval set, not a blog post, settle the final number.

Do I need a reranker in version one?

No. Ship with hybrid search and a reasonable k first. Add a reranker when your evaluation shows the right chunk is being retrieved but ranked too low to make it into the prompt. It is a precision upgrade, not a starting requirement.

How do I handle documents that change often?

Re-embed and re-index changed documents on a schedule or trigger updates when a source changes. Because RAG reads documents fresh at query time, updating knowledge is just updating the index, with no model retraining. Track document versions in your metadata so you can tell which version an answer came from.

What if retrieval returns nothing relevant?

Then your instruction to say "I don't know" earns its keep. A system that admits ignorance beats one that confidently fabricates. Treat frequent no-answer cases as a signal that your corpus has a gap or your chunking is hiding the content, and investigate which.

Key Takeaways

  • Build in order: clean, chunk, embed, store, retrieve, generate, evaluate, then tune.
  • Document cleanup and sensible chunking decide most of your final quality.
  • Add hybrid search in version one to catch exact terms vector search misses.
  • Instruct the model to use only provided context, admit uncertainty, and cite sources.
  • A small evaluation set is what turns tuning from guesswork into measurement.
  • Diagnose every failure as retrieval or generation, then fix the proven weak stage.

Search Articles

Categories

OperationsSalesDeliveryGovernance

Popular Tags

prompt engineeringai fundamentalsai toolsthe difference between AIMLagency operationsagency growthenterprise sales

Share Article

A

Agency Script Editorial

Editorial Team

The Agency Script editorial team delivers operational insights on AI delivery, certification, and governance for modern agency operators.

Related Articles

General

Prompt Quality Decides Whether AI Earns Its Keep

Prompt quality is the single biggest variable in whether AI delivers real work or expensive noise. The model matters, the platform matters — but the prompt you write determines whether you get a first

A
Agency Script Editorial
June 1, 2026·10 min read
General

Counting the Real Cost of Every Token You Send

Tokens and context windows sit at the intersection of AI capability and operational cost—yet most business cases treat them as technical footnotes. That's a mistake that costs real money. Every time y

A
Agency Script Editorial
June 1, 2026·10 min read
General

Rolling Out AI Hallucinations Across a Team

Most teams discover AI hallucinations the hard way — a confident-sounding wrong answer makes it into a client deliverable, a legal brief, or a published report. The damage isn't just to the output; it

A
Agency Script Editorial
June 1, 2026·11 min read

Ready to certify your AI capability?

Join the professionals building governed, repeatable AI delivery systems.

Explore Certification