Question answering over a document store, from a plain-language question to a cited answer, on a laptop.
TextWave is the third case study in the AI program I am taking at Johns Hopkins in fall 2026, after TechTrack and IronClad. The scenario is a company that wants a system that takes a question in plain language, finds the passages in a customer's document store that answer it, and returns an answer a person can read, with the source it came from. Answers have to be relevant on domain-specific and institution-specific material, documents have to come and go as the collection changes, the store has to scale to billions of documents, and every answer has to cite its source.
The pipeline is the standard one. A chunker cuts each document into pieces, a sentence embedding model turns chunks and questions into vectors, a FAISS index returns the nearest chunks, an optional re-ranker reorders them, and a small language model running locally writes the answer from the chunks it is handed. The analysis settles five things in order: the chunking, the index, the generator, the re-ranker, and how many chunks go into the prompt. Each decision reuses the one before it, and where a later result bears on an earlier choice I went back and said so.
I built the retrieval and generation service in Python, then the evaluation harness around it.
The corpus is 150 encyclopedia-style articles, about 696,000 words, and 21 of the files are byte-identical copies of another file. The question file collapses to 513 unique questions with a reference answer, 223 of them yes or no, labelled easy, medium or hard by the person who wrote the answer. I used the same 513 questions for every task so that every comparison is paired, and I ran the generators through a local Ollama server (phi3:mini and qwen2.5:1.5b) at a fixed temperature. The course scores an answer as a true or false match against the reference, by exact match and by a transformer-based equivalence classifier. I report both, and after reading 48 of their disagreements by hand I added a third rule that reads the polarity of a yes or no answer directly and never credits a refusal. Every headline number carries a 95 percent bootstrap interval, and I ran the configurations a decision rests on twice, because generation at this temperature moves the score by about two points between runs.
I measured retrieval on its own first, scoring a chunk as relevant when its text occurs in the article the question was written against. Shorter chunks retrieve the article more often in both families, sentence chunks beat fixed-length chunks of the same length because a fixed window cuts sentences mid-word, and overlap lifts precision in the sentence family only. The service default of 1,500 characters sits 8.8 points of hit@3 below the setting I chose, two sentences per chunk with one sentence of overlap. Among the indexes, HNSW reproduced the exact ranking at a tenth of the cost, and LSH at 256 bits returned only 54 percent of the exact top ten while still finding the article for 93 percent of questions, because an article cut into 255 chunks forgives an approximate neighbour. On synthetic indexes up to 500,000 vectors brute force grew linearly to 26 ms per query and HNSW stayed at a quarter of a millisecond with 99 percent of the exact neighbours.

| chunking | hit@3 | p@3 | hit@3 gap to chosen (95% interval) | p@3 gap to chosen |
|---|---|---|---|---|
| 2 sentences, overlap 1 (chosen) | 94.5 | 83.6 | ||
| 1 sentence | 95.5 | 79.4 | -1.0 (-2.5 to 0.8) | 4.2 (2.5 to 5.7) |
| 3 sentences, overlap 2 | 92.4 | 83.7 | 2.1 (0.6 to 3.7) | -0.1 (-1.4 to 1.1) |
| fixed 250 characters, no overlap | 92.4 | 76.5 | 2.1 (0.4 to 3.9) | 7.0 (5.4 to 8.6) |
| fixed 1,500 characters, overlap 150 (service default) | 85.8 | 73.7 | 8.8 (6.2 to 11.5) | 9.8 (7.7 to 11.8) |

| index | vectors | build s | query ms | overlap with exact top 10 | hit@3 |
|---|---|---|---|---|---|
| brute force | 30,772 | 0.01 | 1.30 | 1.000 | 94.5 |
| HNSW M=32, efSearch 64 | 30,772 | 4.65 | 0.10 | 0.995 | 94.5 |
| LSH 256 bits | 30,772 | 0.01 | 0.06 | 0.540 | 93.0 |
| brute force | 500,000 | 0.53 | 25.86 | 1.000 | 94.5 |
| HNSW M=32, efSearch 64 | 500,000 | 196.98 | 0.25 | 0.990 | 94.2 |
| LSH 256 bits | 500,000 | 0.67 | 1.09 | 0.484 | 91.0 |
The baseline is each model answering the 513 questions from its own training alone, twice each. The two models were level on exact match and on my checked rule, and phi3:mini won the transformer metric by 5 to 7 points in both runs. Reading the disagreements showed where that margin came from. The transformer classifier judges whether an answer is about the right thing rather than whether it is correct, so on yes or no questions it credited 95 percent of phi3's answers, 78 of them opening with the wrong polarity, and phi3 simply answers those questions with a confident "Yes" or "No" more often than qwen does. Exact match has the opposite failure, a reference of "no" matching inside "not" and, later, inside the refusal "No context". That hand check is where the third scorer came from, and it is the one I read first whenever a comparison turns on refusals.

| model and run | exact match | transformer match | checked | checked easy | checked medium | checked hard |
|---|---|---|---|---|---|---|
| phi3:mini, run 1 | 36.5 | 64.3 | 34.7 | 52.9 | 22.3 | 17.9 |
| phi3:mini, run 2 | 37.8 | 63.2 | 35.9 | 53.8 | 23.9 | 18.9 |
| qwen2.5:1.5b, run 1 | 37.4 | 57.5 | 33.1 | 50.7 | 20.1 | 18.9 |
| qwen2.5:1.5b, run 2 | 40.2 | 58.5 | 35.9 | 56.5 | 21.7 | 17.0 |
Handing phi3:mini the top three chunks with the course's context-only prompt added 20 to 26 points on every scorer, ten times the run-to-run movement. The gain was largest on medium questions and smallest on hard ones, where the article was retrieved more often than for any other stratum and the answer still was not in the three chunks. On the 485 questions where a chunk from the right article reached the prompt, the checked score went from 36 to 61 percent; on the 28 where none did, the model obeyed its prompt and scored zero, refusing or guessing from the wrong article. The 45 refusals on questions whose article was retrieved are the more interesting failure: the chunk is from the right article and the fact is not in it, which is a retrieval depth problem and what the re-ranker and the prompt size are for. With retrieval in front of it the smaller model gained as much as phi3 and landed within a point of it, so the generator choice stood but the ground under it moved. Retrieval sets this system's answer quality, not the generator.

| comparison | exact match | transformer match | checked | checked easy | checked medium | checked hard |
|---|---|---|---|---|---|---|
| RAG minus stand-alone, run 1 | 26.3 (21.6 to 30.8) | 15.4 (11.3 to 19.7) | 23.4 (18.7 to 27.9) | 22.4 (15.2 to 30.5) | 29.9 (21.7 to 38.6) | 14.2 (3.8 to 23.6) |
| RAG minus stand-alone, run 2 | 22.8 (18.1 to 27.3) | 15.0 (10.5 to 18.9) | 20.1 (15.2 to 24.6) | 18.4 (10.3 to 26.0) | 27.2 (18.5 to 35.9) | 11.3 (1.9 to 21.7) |
| RAG run 2 minus run 1 | -2.1 (-4.5 to 0.2) | -1.6 (-3.7 to 0.6) | -2.1 (-4.5 to 0.4) | -3.1 (-6.7 to 0.4) | -1.1 (-5.4 to 3.3) | -1.9 (-6.6 to 2.8) |
The index returned ten candidates, a re-ranker reordered them, and the first three went to the model. On the article-level retrieval metrics every re-ranker landed within a point or two of the plain index order, because a re-ranker can only reorder ten candidates that already hold the right article 95 percent of the time. On the answers, the cross-encoder was the best setting on all three scorers, 3.9 points of checked match over the index order, and the gain held in a second run on every scorer. I traced the gap between the two layers to the relevance rule: a chunk about Lincoln's childhood counts as relevant to a question about his assassination, but the generator needs the sentence that holds the answer. Measuring that directly, the cross-encoder put the answer in the prompt for 63 percent of the free-text questions against 57 for the index order, while its article recall moved 0.4 points. It costs 8 ms per question, and that cost does not grow with the corpus.

| re-ranker | exact match | transformer match | checked | refusals | checked minus index order (95% interval) |
|---|---|---|---|---|---|
| none (index order) | 62.8 | 79.7 | 58.1 | 58 | |
| cross-encoder | 66.7 | 83.2 | 62.0 | 49 | 3.9 (0.8 to 7.4) |
| hybrid, TF-IDF weight 0.1 | 65.3 | 82.1 | 61.8 | 54 | 3.7 (0.8 to 7.4) |
| hybrid, weight 0.3 | 65.1 | 82.8 | 61.2 | 56 | 3.1 (-0.2 to 6.8) |
| hybrid, weight 0.5 | 63.5 | 82.1 | 60.2 | 54 | 2.1 (-0.8 to 5.5) |
| TF-IDF | 62.4 | 81.5 | 57.7 | 66 | -0.4 (-3.7 to 3.1) |
| bag of words | 61.8 | 81.1 | 57.7 | 61 | -0.4 (-3.3 to 2.9) |
| sequential, TF-IDF top 3 then cross-encoder | 62.8 | 81.1 | 58.5 | 66 | 0.4 (-2.9 to 4.3) |
| sequential, top 5 then cross-encoder | 62.4 | 82.8 | 58.7 | 53 | 0.6 (-2.5 to 3.7) |
With the cross-encoder ordering the ten candidates, I handed the model the first m of them for m from 1 to 10. One chunk is not enough: the model refused 92 times and scored 9 points below three chunks. A second chunk recovered almost all of it, and from two to ten no scorer moved by more than 1.6 points, apart from a dip at eight that two more chunks undid. Each extra chunk added about 60 prompt tokens, about 0.3 s at the median, and one more source for a user to check. My rule took the smallest m the scores could not separate from the best, and a second run of two and three chunks confirmed the tie: the sign of every difference flipped between runs, and with both runs averaged no difference was larger than 0.4 points. The eight-chunk dip taught me something about the output rather than the retrieval. As the prompt grows, phi3 starts to open answers with "Answer:" as if continuing a transcript, 36 times at eight chunks, and a client that parses the first word of the answer would have to strip a label the model adds only on long prompts.

| chunks in prompt | exact match | transformer match | checked | refusals | median prompt tokens | median s | checked minus m=3 (95% interval) |
|---|---|---|---|---|---|---|---|
| 1 | 57.9 | 79.1 | 53.0 | 92 | 154 | 1.04 | -9.0 (-12.5 to -5.5) |
| 2 | 65.7 | 81.7 | 61.8 | 49 | 216 | 1.29 | -0.2 (-3.1 to 2.7) |
| 3 | 66.7 | 83.2 | 62.0 | 49 | 282 | 1.55 | |
| 5 | 66.1 | 81.7 | 61.2 | 54 | 406 | 2.23 | -0.8 (-3.7 to 2.3) |
| 8 | 64.7 | 82.7 | 58.3 | 52 | 592 | 2.95 | -3.7 (-6.8 to -0.6) |
| 10 | 66.1 | 81.9 | 61.6 | 43 | 704 | 3.72 | -0.4 (-3.3 to 2.7) |
Two generators that differ by a factor of two in size land within a point of each other once the right chunks are in front of them, and the 20 to 26 point gain from retrieval is ten times the noise between runs. The settings worth tuning are the ones that decide what reaches the prompt: the chunking, the re-ranker, and the number of chunks.
Every re-ranker looked the same on article-level recall and the cross-encoder was four points better on the answers, because it put the sentence that holds the answer in the prompt 6.6 points more often. A retrieval metric that needs only the reference answers, and that sees the sentence rather than the article, is the one I would tune on next time.
The transformer metric rewards a confident wrong polarity, exact match rewards the refusal the prompt asks for, and the model's own output format drifts on long prompts. Reading 48 disagreements by hand produced a third rule that arbitrates where the shipped scorers split, and I say which scorer each decision rests on.
Every decision in the report, the measurement it rests on, the requirement it serves, and the alternative I rejected.
The evaluation set is 513 questions about 21 articles, and the model had read about all of them before it saw a single chunk, so the numbers say less about institution-specific documents than the requirement asks. The scaling past 30,772 vectors is synthetic, and the billion-vector memory figures are arithmetic, not measurements. Two of the scorers are the course's and the third is my own rule from a hand check, and I did no manual review or LLM judge of the final configuration. I ran the configurations a decision rests on twice and everything else once, and the run-to-run spread is about two points, so single-run differences smaller than that are not evidence. Latencies are from one laptop with the generator on its GPU and FAISS on one CPU thread. Removal of documents is designed and not built, and whether a cited chunk actually supports the answer it is attached to is untested. Once the system is live there is no answer key, so I would track the refusal rate, the share of answer words that occur in the cited passage, and the re-ranker's top score, calibrated first against a hand-graded sample. The failure I worry about most never arises in this benchmark: two editions of the same policy side by side, identical except for one figure, where the model would quote whichever ranked higher.
Course repositories stay private under the university's rules, so this page summarizes my results and does not link the code.