Your Requirements Doc Is 400 Pages Long. Your AI Agent Just Gave Up.
From the publisher’s feed, collected in the ZeroLabs newsroom.
Here is a scene a lot of QA testers know too well:You open GitHub Copilot Chat (or whatever AI coding assistant you use), paste in your massive requirements document, and type:“Generate test cases for the login and payment flow.”Copilot chews on it for a second, and then:It times out or throws a “context window exceeded” error.It gives you generic, superficial test cases that clearly skipped 90% of your actual acceptance criteria.It crawls at a snail’s pace because it is reading hundreds of pages of unneeded text every time you ask a question.If this sounds familiar, you are not doing anything wrong. You just ran headfirst into a fundamental LLM bottleneck: AI agents do not have infinite attention, and stuffing giant documents into their prompt is slow, expensive, and frankly wasteful when all you need is the two paragraphs defining the payment retry rules.The good news? This is a solved problem. Search engines and chatbot engineers have tackled the “needle in a haystack” challenge for years. We can borrow their playbooks. Let’s break down the best practical options — from production-grade to dead simple.The Core Fix: Stop Feeding It EverythingThe solution across every pattern is the same: search first, generate second.Instead of dumping the encyclopedia into your prompt, pull only the specific slice relevant to the feature you are testing. Hand that exact snippet to Agent alongside your test generation instructions.This approach is known as Retrieval-Augmented Generation (RAG). Less text in means faster responses, fewer tokens billed, and far higher test fidelity because Agent is not hallucinating through 380 pages of irrelevant background info.Let’s look at four ways to set this up.Option 1: Classic Vector RAG (Semantic Search)This is the standard pattern teams talk about when they say “RAG.”How it works:Break your requirements into modular chunks (around 300–500 words each).Convert each chunk into an embedding vector (a mathematical representation of its meaning) using an embedding model.Store those vectors in a lightweight vector store (like Chroma, FAISS, or Pinecone).When you ask: “Write edge cases for checkout failure,” your query is embedded, the database finds chunks with matching semantic meaning, and only those 2–3 chunks are fed into Agent.In Practice:Say your doc covers User Authentication, Payment Processing, Retry and Timeout Rules, and Notification Settings. If you query for payment recovery tests, semantic search identifies Payment Processing and Retry and Timeout Rules as conceptual matches, ignoring everything else. Agent receives 700 words rather than 50,000.When to use: Massive, evolving documentation where your search terms might not match the document word-for-word (e.g., you ask about “declined cards” but the doc calls it “unsuccessful transaction processing”).The Catch: Requires spinning up an embedding pipeline, picking a vector store, and running indexing scripts. Great for engineering platforms, but often overkill for a QA engineer who just wants test cases this afternoon.Option 2: Vector-less RAG with BM25 (Smart Keyword Search)You do not actually need vectors or GPUs to do retrieval. Good old-fashioned probabilistic keyword search works remarkably well.BM25 is the battle-tested ranking algorithm powering enterprise search tools like Elasticsearch. It scores text chunks based on keyword frequency, but balances that by down-weighting terms that appear everywhere and rewarding chunks that contain rare, specific terms.How it works:Split your documents into individual section files.Index them locally with a small library like rank-bm25.Query the index using your test prompt keywords.Feed the top 2 ranked files directly into Agent.In Practice:You ask for “test scenarios for OTP timeout lockout.” BM25 looks across your files, flags files containing the exact tokens OTP, timeout, and lockout, and instantly surfaces auth_otp_spec.md. No embeddings, no external API costs, and it runs in less than 20 lines of Python.When to use: Highly technical requirements where QA engineers naturally query with the exact terms defined in the spec.The Catch: Zero tolerance for synonyms. If the spec says “abort transaction” and you search for “cancel payment,” BM25 will score it lower because the exact tokens do not match.Option 3: Structured Chunking + Keyword Index JSONThis is the lightweight, zero-infra approach. It gives you full control and works natively inside VS Code with GitHub Copilot Chat.Instead of arbitrary word-count splits that cut sentences in half, we chunk logically by Markdown headings (#, ##, or ###). Each section becomes its own bite-sized file, accompanied by a generated keyword index.Automated Chunking with Python (Bag-of-Words)Here is a clean Python script that splits a requirements document on Markdown headers, extracts the most prominent non-trivial keywords (bag-of-words), and writes an index JSON:import osimport reimport jsonfrom collections import CounterSTOPWORDS = { "the", "and", "for", "with", "that", "this", "from", "are", "user", "system", "shall", "must", "will", "should", "when"}def chunk_by_markdown_headers(markdown_text): # Split on lines starting with ## or ### sections = re.split(r'(?m)(?=^#{2,3}\s+)', markdown_text) return [s.strip() for s in sections if s.strip()]def extract_keywords(text, top_n=6): words = re.findall(r'[a-zA-Z]{3,}', text.lower()) filtered = [w for w in words if w not in STOPWORDS] counts = Counter(filtered) return [word for word, _ in counts.most_common(top_n)]def build_index(doc_path, output_dir="chunks"): os.makedirs(output_dir, exist_ok=True) with open(doc_path, "r", encoding="utf-8") as f: content = f.read() chunks = chunk_by_markdown_headers(content) index = [] for i, chunk in enumerate(chunks, 1): first_line = chunk.splitlines()[0].replace("#", "").strip() filename = f"chunk_{i:02d}_{re.sub(r'\W+', '_', first_line).lower()}.md" filepath = os.path.join(output_dir, filename) with open(filepath, "w", encoding="utf-8") as f: f.write(chunk) index.append({ "chunk_id": i, "title": first_line, "file": filepath, "keywords": extract_keywords(chunk) }) with open(os.path.join(output_dir, "requirements_index.json"), "w") as f: json.dump(index, f, indent=2) return indexif __name__ == "__main__": build_index("system_requirements.md")What the Generated Index Looks Like:[ { "chunk_id": 1, "title": "User Authentication and OTP", "file": "chunks/chunk_01_user_authentication_and_otp.md", "keywords": ["password", "lockout", "biometric", "expiry", "session", "token"] }, { "chunk_id": 2, "title": "Payment Processing and Retries", "file": "chunks/chunk_02_payment_processing_and_retries.md", "keywords": ["gateway", "refund", "stripe", "timeout", "reversal", "invoice"] }]The Copilot Power Move: #file VariableOnce your docs are chunked into your repository or test workspace, you do not have to copy and paste anything. In GitHub Copilot Chat, you can reference the specific chunk directly using the #file variable:“Using #file:chunks/chunk_02_payment_processing_and_retries.md, generate positive and negative boundary test cases for transaction timeouts.”Copilot pulls only that file into memory, keeping token counts minimal, execution immediate, and hallucination rates near zero.Option 4: Ditch Binary Files — Use CSVs and Markdown Instead of Excel and WordA hidden reason AI assistants choke on requirements is the format.Binary formats like .xlsx and .docx are zipped archives packed with XML trees, styling tags, font references, cell bounds, and metadata. When an LLM or extension tries to extract their contents, token counters spike just to parse the structural bloat.Plain text formats like .csv and .md eliminate all formatting overhead:For Massive Word Docs: Export or convert them directly to Markdown (.md). Markdown headers cleanly translate to test hierarchy markers, making chunking automatic.For Massive Multi-Sheet Workbooks: Avoid feeding an entire 15-tab workbook to the model. Break the workbook down by saving each worksheet as an independent CSV file.Indexing Multiple CSV WorksheetsPair your exported worksheet CSVs with an explicit mapping index:{ "worksheets": [ { "file": "specs/auth_matrix.csv", "module": "Authentication & Access Control", "keywords": ["roles", "rbac", "permissions", "admin", "token_refresh"] }, { "file": "specs/payment_gateways.csv", "module": "Payment Gateway Integration", "keywords": ["webhook", "settlement", "idempotency", "currency_conversion"] }, { "file": "specs/error_codes.csv", "module": "Error Code Definitions", "keywords": ["http_500", "retry_after", "rate_limit", "unauthorized"] } ]}Whenever you need tests for token refresh or RBAC, you load auth_matrix.csv alone. Copilot receives clean tabular rows with zero XML luggage.Decision Guide: Which One Fits Your Team?Enterprise test suite with thousands of pages & varying jargon→ Best approach: Classic Vector RAG→ Why: Finds conceptual matches even when test prompt words don’t match document terms.Strict technical specifications with standardized vocabulary→ Best approach: Vector-less BM25→ Why: Near-instant retrieval, 100% local, zero embedding pipeline costs.Individual QA tester working locally in VS Code / IDE→ Best approach: Heading Chunking + Index JSON→ Why: Simplest execution. Use #file in Copilot Chat for precise context targeting.Legacy requirements stuck in heavy Word or Excel documents→ Best approach: CSV / Markdown Conversion→ Why: Baseline necessity. Cuts 60–80% of token bloat before applying any search method.The Real TakeawayUsing AI for test generation is a massive productivity unlock, but your agent is only as good as the context you hand it.Do not ask Copilot to read an entire 400-page specification to write three test assertions for a login timeout. Search first, generate second. Give the model the targeted section, keep your tokens low, and watch your test generation speed and accuracy multiply.Your Requirements Doc Is 400 Pages Long. Your AI Agent Just Gave Up. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.