Joel Stevick

Exercises · RAG

Exercise 1: Filters on search

Add file, from_page and to_page to the MCP server's search_documents tool, so a client can search one file and a range of its pages.

About an hour. You'll use TypeScript, a SQL WHERE clause and git.

RAG Starts at 0c6a395 · Your branch 1-filters-on-search · Test demo/tests/search-filters.test.ts

Watch first

Watch on YouTube (17 min)

The problem

search_documents is the demo MCP server's read-only search: it takes a query, runs the pipeline's hybrid retrieval over every chunk of the demo's uploaded PDFs, and returns the best passages with their file and page. A chunk is a stretch of one page's text, stored as a row in the chunks table in D1 with its file name and page number.

The tool's input schema has three properties: query, limit and cursor. The SDK validates arguments with that schema, a zod object, and zod ignores any property the object does not name. So when a client passes file, the call succeeds and the argument is gone before the handler runs.

That happened in a real run of the repository's search loop (examples/search-loop): Claude was asked about one document, passed file to narrow the search, and read passages from every document. The same call against the starting commit, with two six-page PDFs uploaded, shows it:

Arguments

{ "query": "deposit refunded", "limit": 3, "file": "policy.pdf" }

What the model reads

[handbook.pdf, page 1]
Handbook page 1. The deposit is refunded within 1 weeks.

[handbook.pdf, page 2]
Handbook page 2. The deposit is refunded within 2 weeks.

[handbook.pdf, page 3]
Handbook page 3. The deposit is refunded within 3 weeks.

No error, and no passage from policy.pdf. The model has no way to tell its filter was ignored.

When it is done

  • search_documents takes three more optional arguments: file, the file's name as the passages show it, and from_page and to_page, whole numbers from 1. Any of them may be given alone.
  • A search with a filter returns passages from that file and those pages only.
  • An unknown file name is an error that lists the files there are, and from_page after to_page is an error, so the model can correct the call.
  • A cursor from a filtered search is accepted only by the same query with the same filters.
  • A search with no filter returns what it returned before.

How it works

Where the filter goes

retrieval in demo/src/app.ts does the search in two halves. It reads the demo's chunks from D1 (all), and it asks Vectorize for the ids of the 48 chunks whose vectors are closest to the question's vector (near). It passes both to fuseKeywordAndVector in demo/src/retrieval.ts, which ranks all by keyword with BM25 and merges that ranking with near by reciprocal rank fusion: each chunk scores the sum of 1 / (60 + rank) over the two lists it appears in.

Before it merges, fuseKeywordAndVector keeps a vector id only if that id is one of the chunks in all (near.filter((id) => byId.has(id))). That line exists so a vector for a deleted chunk is never shown, and it makes the filter simple: narrow the D1 read with WHERE file = ? AND page >= ? AND page <= ?, and every vector result outside the filter is dropped at the merge. The vector search itself is not changed.

Names, and the error the model reads

The files table stores each file under the name the browser sent. The tool shows the model that name after clean, which turns control characters and line breaks into spaces and cuts it to 120 characters, so a file name can never carry a second line into the model's context. The file argument is therefore matched against the cleaned names, and the filter passed to retrieval is the stored name that matched.

A tool error goes back to the model as the result's text with isError: true. The text names the files there are, so the model's next call can use a real name.

The cursor

A cursor is the opaque string a search returns as nextCursor when more passages match; passing it back returns the passages after the ones already shown. It holds an offset and a tag: the first 16 hex characters of the SHA-256 of the demo id and the query. offsetOf recomputes the tag and refuses a cursor whose tag differs, so a cursor cannot be replayed against another search. The filters change which passages a search returns, so they go into the tag too.

Steps

  1. Fork joelstevick-demo-rag-pipeline on GitHub, clone your fork, then cd into it. With the GitHub CLI (gh), signed in, this one command does both:

    gh repo fork AiFirstDevelopment/joelstevick-demo-rag-pipeline --clone && cd joelstevick-demo-rag-pipeline

    You need Node 20 or later.

  2. Then, in your clone, make your branch at the starting commit and run the suite; every test passes:

    git fetch origin
    git checkout -b 1-filters-on-search 0c6a395
    npm install
    npm test

    If your fork is older than the starting commit, press Sync fork on GitHub first.

  3. Add the test file, demo/tests/search-filters.test.ts, whole as The test shows it, and run it: six of its seven tests fail.
  4. In demo/src/app.ts, above retrieval, add a SearchFilter interface with optional file, fromPage and toPage.
  5. Give retrieval a fifth parameter, filter: SearchFilter = {}, and build the D1 query's WHERE clause and its bound values from it, one condition per field that is set.
  6. In demo/src/mcp.ts, import SearchFilter from ./app.
  7. Add the filters to the string that cursorFor and offsetOf hash, the same in both.
  8. Add file, from_page and to_page to the tool's input schema, each with a .describe(): the description is how the model learns the argument exists.
  9. In the tool's handler, find the file whose cleaned name matches, return an error for an unknown name or a backwards range, and pass the filter to offsetOf, retrieval and cursorFor.
  10. Run npm run typecheck and npm test: all seven of the exercise's tests pass, and so does the rest of the suite.

With Claude Code

A prompt that makes Claude Code coach rather than solve:

I'm doing exercise 1 at https://joelstevick.com/learn/source/exercises/filters-on-search. First check my clone is set up as the page's "Before you start" says: on the branch 1-filters-on-search made at 0c6a395 (run git fetch origin first if that commit is missing), npm install run, and npm test passing; if it isn't, tell me the commands. Then read the page except "Show me". Create its test file, demo/tests/search-filters.test.ts, whole, from the one Show me step that creates it, then coach me through the steps; don't write the change for me and don't look at the solution/1-filters-on-search branch.

The test

The tests run the MCP server through the Worker's routes, signed in through the whole OAuth flow, with two six-page PDFs whose passages use the same words, so only a filter tells them apart. Run them alone with:

npx vitest run --config demo/vitest.config.ts demo/tests/search-filters.test.ts

demo/tests/search-filters.test.ts lines 1–83 on GitHub

// Copyright (c) 2026 Joel Stevick// SPDX-License-Identifier: MIT// Licensed under the MIT License: https://opensource.org/licenses/MIT// Exercise 1, filters on search: search_documents narrowed to one file, a range of pages, or both, through the// Worker's routes with scripted models, a local D1 and the whole OAuth flow (the helpers of mcp.test.ts).import { afterEach, beforeEach, describe, expect, it } from 'vitest'import { client, closeClients, connect, newDemo, upload, world, type World } from './mcp-support'let w: WorldbeforeEach(async () => { w = await world() })afterEach(closeClients)type Passage = { file: string; page: number; text: string; uri: string }type Found = { passages: Passage[]; nextCursor?: string }/** A demo with two six-page PDFs that use the same words, so only a filter tells their passages apart, and a client signed in to it. */async function twoFiles() {  const demo = await newDemo(w, 'fp_a')  await upload(w, demo.key, 'handbook.pdf', Array.from({ length: 6 }, (_, i) => `Handbook page ${i + 1}. The deposit is refunded within ${i + 1} weeks.`))  await upload(w, demo.key, 'policy.pdf', Array.from({ length: 6 }, (_, i) => `Policy page ${i + 1}. The deposit is refunded within ${i + 1} days.`))  return client(w, (await connect(w, demo.key)).token)}const text = (result: { content?: unknown }) => ((result.content ?? []) as { type: string; text?: string }[]).map((item) => item.text ?? '').join('\n')describe('filters on search', () => {  it('no filter searches both files, as before', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10 } })).structuredContent as Found    expect(new Set(found.passages.map((p) => p.file))).toEqual(new Set(['handbook.pdf', 'policy.pdf']))  })  it('file returns passages of that file only', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, file: 'policy.pdf' } })).structuredContent as Found    expect(found.passages.length).toBeGreaterThan(0)    for (const passage of found.passages) expect(passage.file).toBe('policy.pdf')  })  it('from_page and to_page return passages inside that range only', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, from_page: 2, to_page: 3 } })).structuredContent as Found    expect(found.passages.length).toBeGreaterThan(0)    for (const passage of found.passages) expect([2, 3]).toContain(passage.page)  })  it('file and pages together narrow to both', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, file: 'handbook.pdf', from_page: 5 } })).structuredContent as Found    expect(found.passages.map((p) => `${p.file} ${p.page}`).sort()).toEqual(['handbook.pdf 5', 'handbook.pdf 6'])  })  it('an unknown file is an error that names the files there are', async () => {    const mcp = await twoFiles()    const result = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit', file: 'lease.pdf' } })    expect(result.isError, text(result)).toBe(true)    expect(text(result)).toBe('There is no file named lease.pdf. The files are: handbook.pdf, policy.pdf.')  })  it('from_page after to_page is an error', async () => {    const mcp = await twoFiles()    const result = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit', from_page: 4, to_page: 2 } })    expect(result.isError, text(result)).toBe(true)    expect(text(result)).toBe('from_page (4) is after to_page (2).')  })  it('a cursor from a filtered search is refused by a search with other filters, and accepted by the same one', async () => {    const mcp = await twoFiles()    const first = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, file: 'policy.pdf' } })).structuredContent as Found    expect(first.nextCursor).toBeTypeOf('string')    // The same query without the filter: the cursor is not from this search.    const other = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, cursor: first.nextCursor } })    expect(other.isError).toBe(true)    expect(text(other)).toContain('That cursor is not from this search.')    // The same query and filter: the next passages, still from that file.    const next = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, file: 'policy.pdf', cursor: first.nextCursor } })).structuredContent as Found    expect(next.passages.length).toBe(2)    for (const passage of next.passages) expect(passage.file).toBe('policy.pdf')  })})

On the starting commit six of the seven fail: the filters are ignored, so passages from both files come back and no call is an error. The first test, no filter, passes on both commits, and it is what shows the change kept the old behaviour.

Seeing it in action

On your machine

Run your copy on your machine: the Worker at http://localhost:8787 with a local database, and the repository's two sample PDFs, a lease and the building's house rules, which both talk about notice, deposits and pets. npm run local keeps running, so the other three commands go in a second terminal.

Do it once on your branch before you change anything, and again when the test passes. The Worker reloads your change; start Claude Code again so it reads the tool's new schema.

In one terminal:

npm run local

In a second terminal, one command at a time:

Load the two sample PDFs. The seed prints your demo's key, which the consent page in your browser asks for the first time Claude Code or the search loop connects.

npm run local:seed -- examples/pdfs/*.pdf

Add your copy's MCP server to Claude Code:

claude mcp add --transport http my-docs http://localhost:8787/mcp/demo

The search loop needs your own Anthropic API key: run export ANTHROPIC_API_KEY= with your key after the equals sign, then ask it the question:

npm run search -- "What does page 9 of lease.pdf say about ending the lease early?"

Then ask Claude Code the same question:

What does page 9 of lease.pdf say about ending the lease early?

Claude Code shows each search_documents call it makes, and the search loop prints them. These are the search loop's, from real runs:

Before the change

→ search_documents {"query":"ending the lease early, early termination","limit":10}
→ search_documents {"query":"terminate lease before end of term notice penalty fee","limit":10}

The schema offers no file and no page, so the model searches both documents, twice.

After the change

→ search_documents {"query":"ending the lease early termination","file":"lease.pdf","from_page":9,"to_page":9}

One call, narrowed to page 9 of lease.pdf.

In the tests

A filtered search

The same two PDFs, searched with a file and a page range. The result's structuredContent:

Arguments

{ "query": "deposit refunded", "limit": 3, "file": "policy.pdf", "from_page": 2, "to_page": 3 }

Result

{
  "passages": [
    {
      "file": "policy.pdf",
      "page": 2,
      "text": "Policy page 2. The deposit is refunded within 2 days.",
      "uri": "demo://files/2/pages/2"
    },
    {
      "file": "policy.pdf",
      "page": 3,
      "text": "Policy page 3. The deposit is refunded within 3 days.",
      "uri": "demo://files/2/pages/3"
    }
  ]
}

Two passages, though the limit is three: only two chunks are inside the filter, and there is no nextCursor because nothing is left.

A name that is not there

With isError set, the session goes on, and the text names the files, so the model can retry with one of them.

Arguments

{ "query": "deposit", "file": "lease.pdf" }

Result

{
  "content": [
    {
      "type": "text",
      "text": "There is no file named lease.pdf. The files are: handbook.pdf, policy.pdf."
    }
  ],
  "isError": true
}

These are the server's real results on the solution commit, from the test suite's local Worker. To print them yourself, add a console.log of each callTool result to a test in search-filters.test.ts and run it with the command above.

Show me

The solution, in 9 steps
0 Before you start: clone your fork, branch at 0c6a395, run npm install and npm test.

Fork joelstevick-demo-rag-pipeline on GitHub, clone your fork, then cd into it. With the GitHub CLI (gh), signed in, this one command does both:

gh repo fork AiFirstDevelopment/joelstevick-demo-rag-pipeline --clone && cd joelstevick-demo-rag-pipeline

Then, in your clone, make your branch at the starting commit and run the suite; every test passes:

git fetch origin
git checkout -b 1-filters-on-search 0c6a395
npm install
npm test

If your fork is older than the starting commit, press Sync fork on GitHub first.

1 Create demo/tests/search-filters.test.ts.

demo/tests/search-filters.test.ts lines 1–83 on GitHub

// Copyright (c) 2026 Joel Stevick// SPDX-License-Identifier: MIT// Licensed under the MIT License: https://opensource.org/licenses/MIT// Exercise 1, filters on search: search_documents narrowed to one file, a range of pages, or both, through the// Worker's routes with scripted models, a local D1 and the whole OAuth flow (the helpers of mcp.test.ts).import { afterEach, beforeEach, describe, expect, it } from 'vitest'import { client, closeClients, connect, newDemo, upload, world, type World } from './mcp-support'let w: WorldbeforeEach(async () => { w = await world() })afterEach(closeClients)type Passage = { file: string; page: number; text: string; uri: string }type Found = { passages: Passage[]; nextCursor?: string }/** A demo with two six-page PDFs that use the same words, so only a filter tells their passages apart, and a client signed in to it. */async function twoFiles() {  const demo = await newDemo(w, 'fp_a')  await upload(w, demo.key, 'handbook.pdf', Array.from({ length: 6 }, (_, i) => `Handbook page ${i + 1}. The deposit is refunded within ${i + 1} weeks.`))  await upload(w, demo.key, 'policy.pdf', Array.from({ length: 6 }, (_, i) => `Policy page ${i + 1}. The deposit is refunded within ${i + 1} days.`))  return client(w, (await connect(w, demo.key)).token)}const text = (result: { content?: unknown }) => ((result.content ?? []) as { type: string; text?: string }[]).map((item) => item.text ?? '').join('\n')describe('filters on search', () => {  it('no filter searches both files, as before', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10 } })).structuredContent as Found    expect(new Set(found.passages.map((p) => p.file))).toEqual(new Set(['handbook.pdf', 'policy.pdf']))  })  it('file returns passages of that file only', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, file: 'policy.pdf' } })).structuredContent as Found    expect(found.passages.length).toBeGreaterThan(0)    for (const passage of found.passages) expect(passage.file).toBe('policy.pdf')  })  it('from_page and to_page return passages inside that range only', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, from_page: 2, to_page: 3 } })).structuredContent as Found    expect(found.passages.length).toBeGreaterThan(0)    for (const passage of found.passages) expect([2, 3]).toContain(passage.page)  })  it('file and pages together narrow to both', async () => {    const mcp = await twoFiles()    const found = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 10, file: 'handbook.pdf', from_page: 5 } })).structuredContent as Found    expect(found.passages.map((p) => `${p.file} ${p.page}`).sort()).toEqual(['handbook.pdf 5', 'handbook.pdf 6'])  })  it('an unknown file is an error that names the files there are', async () => {    const mcp = await twoFiles()    const result = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit', file: 'lease.pdf' } })    expect(result.isError, text(result)).toBe(true)    expect(text(result)).toBe('There is no file named lease.pdf. The files are: handbook.pdf, policy.pdf.')  })  it('from_page after to_page is an error', async () => {    const mcp = await twoFiles()    const result = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit', from_page: 4, to_page: 2 } })    expect(result.isError, text(result)).toBe(true)    expect(text(result)).toBe('from_page (4) is after to_page (2).')  })  it('a cursor from a filtered search is refused by a search with other filters, and accepted by the same one', async () => {    const mcp = await twoFiles()    const first = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, file: 'policy.pdf' } })).structuredContent as Found    expect(first.nextCursor).toBeTypeOf('string')    // The same query without the filter: the cursor is not from this search.    const other = await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, cursor: first.nextCursor } })    expect(other.isError).toBe(true)    expect(text(other)).toContain('That cursor is not from this search.')    // The same query and filter: the next passages, still from that file.    const next = (await mcp.callTool({ name: 'search_documents', arguments: { query: 'deposit refunded', limit: 2, file: 'policy.pdf', cursor: first.nextCursor } })).structuredContent as Found    expect(next.passages.length).toBe(2)    for (const passage of next.passages) expect(passage.file).toBe('policy.pdf')  })})
2 In demo/src/app.ts, insert these 3 lines at line 470 (below the Options interface).

demo/src/app.ts becomes lines 470–472 · on GitHub

/** What `retrieval` may be narrowed to: the stored name of one file, and the first and last page, each optional. */export interface SearchFilter { file?: string; fromPage?: number; toPage?: number }
3 In demo/src/app.ts, replace lines 483–486 with these 13 lines (around export async function retrieval(question: …).

demo/src/app.ts becomes lines 483–495 · on GitHub

 * * `filter` narrows the search to one file, a range of pages, or both. It is applied to the chunks read from * D1 only: `fuseKeywordAndVector` keeps a vector result only if its id is among those chunks, so the vector * results outside the filter are dropped there. */export async function retrieval(question: string, env: Env, models: Models, demo: Demo, filter: SearchFilter = {}): Promise<{ all: Chunk[]; retrieved: Chunk[] }> {  // `all`: every chunk of this demo's documents, from D1, for keyword search, narrowed to the filter's file and pages.  const where = ['demo_id = ?']  const values: (string | number)[] = [demo.id]  if (filter.file !== undefined) { where.push('file = ?'); values.push(filter.file) }  if (filter.fromPage !== undefined) { where.push('page >= ?'); values.push(filter.fromPage) }  if (filter.toPage !== undefined) { where.push('page <= ?'); values.push(filter.toPage) }  const all = (await env.DB.prepare(`SELECT id, file, page, text, seq FROM chunks WHERE ${where.join(' AND ')} ORDER BY rowid`).bind(...values).all<Chunk>()).results
4 In demo/src/mcp.ts, replace line 16 with this line (starting import { ask, asText, json, LIMITS, remove…).

demo/src/mcp.ts becomes line 16 · on GitHub

import { ask, asText, json, LIMITS, remove, retrieval, sha256, type Demo, type Env, type Options, type SearchFilter } from './app'
5 In demo/src/mcp.ts, replace lines 151–166 with these 19 lines (starting /** A search cursor: where the next page s…).

demo/src/mcp.ts becomes lines 151–169 · on GitHub

/** What a cursor is tied to: the demo, the query and the filters, one per line, so a cursor from one search is refused by another. */const searchKey = (demo: Demo, query: string, filter: SearchFilter) => [demo.id, query, filter.file ?? '', filter.fromPage ?? '', filter.toPage ?? ''].join('\n')/** A search cursor: where the next page starts, tied to the demo, the query and the filters it came from. */async function cursorFor(demo: Demo, query: string, offset: number, filter: SearchFilter = {}): Promise<string> {  return btoa(JSON.stringify({ o: offset, t: (await sha256(searchKey(demo, query, filter))).slice(0, 16) }))}/** The offset a cursor names, or an invalid-params error (inside the tool, the SDK returns it as an isError result). */async function offsetOf(demo: Demo, query: string, cursor: string | undefined, filter: SearchFilter = {}): Promise<number> {  // No cursor means start at the top.  if (cursor === undefined) return 0  // Decode the cursor if it can be decoded.  let parsed: { o?: unknown; t?: unknown } = {}  try { parsed = JSON.parse(atob(cursor)) as typeof parsed } catch { /* not ours: refused below */ }  // It must hold a valid offset and the tag for this demo, query and filters.  const tag = (await sha256(searchKey(demo, query, filter))).slice(0, 16)
6 In demo/src/mcp.ts, replace line 257 with these 4 lines (starting cursor: z.string().optional().describe('Th…).

demo/src/mcp.ts becomes lines 257–260 · on GitHub

      cursor: z.string().optional().describe('The nextCursor of an earlier call with the same query and filters, for the passages after it.'),      file: z.string().min(1).max(MAX_NAME).optional().describe('Search only this file: its name as the passages show it, such as handbook.pdf.'),      from_page: z.number().int().min(1).optional().describe('Search only from this page on.'),      to_page: z.number().int().min(1).optional().describe('Search only up to this page.'),
7 In demo/src/mcp.ts, replace lines 267–271 with these 11 lines (starting }, async ({ query, limit, cursor }) => {).

demo/src/mcp.ts becomes lines 267–277 · on GitHub

  }, async ({ query, limit, cursor, file: fileName, from_page: fromPage, to_page: toPage }) => {    // No point searching an empty demo.    const files = await filesOf(env, demo)    if (files.length === 0) return failed('There are no documents in this demo yet. Upload a PDF first.')    // The file filter names a file as the passages show it; find the stored name it stands for.    const named = fileName === undefined ? undefined : files.find((file) => clean(file.name) === clean(fileName))    if (fileName !== undefined && named === undefined) return failed(`There is no file named ${clean(fileName)}. The files are: ${files.map((file) => clean(file.name)).join(', ')}.`)    if (fromPage !== undefined && toPage !== undefined && fromPage > toPage) return failed(`from_page (${fromPage}) is after to_page (${toPage}).`)    const filter: SearchFilter = { file: named?.name, fromPage, toPage }
8 In demo/src/mcp.ts, replace lines 279–283 with these 5 lines (starting const offset = await offsetOf(demo, query,…).

demo/src/mcp.ts becomes lines 279–283 · on GitHub

    const offset = await offsetOf(demo, query, cursor, filter)    if (!(await hit(env, `search:${demo.id}`, day(), SEARCHES_PER_DAY))) return failed(`This demo has made its ${SEARCHES_PER_DAY} searches for today. Try again tomorrow.`)    // Run the retrieval and match each passage back to its file.    const { retrieved } = await retrieval(query, env, run.models, demo, filter)
9 In demo/src/mcp.ts, replace line 300 with this line (starting const nextCursor = next < retrieved.length…).

demo/src/mcp.ts becomes line 300 · on GitHub

    const nextCursor = next < retrieved.length ? await cursorFor(demo, query, next, filter) : undefined

Compare your work

The solution is the branch solution/1-filters-on-search, commit eb31c94. Its whole diff is on GitHub. From your clone:

git fetch https://github.com/AiFirstDevelopment/joelstevick-demo-rag-pipeline solution/1-filters-on-search
git add -A
git --no-pager diff --cached -R FETCH_HEAD

An empty diff means your work matches the solution. Otherwise each file that differs starts with diff --git: a line marked + (green) is in the solution and missing from your copy, and a line marked - (red) is in your copy and not in the solution. Find the step that writes those lines in Show me and do it again.

Going further

  • Vectorize can filter by metadata itself. Store file and page as metadata on each vector at upload, create metadata indexes for them, and pass the filter to the query, so all 48 nearest results come from inside the filter instead of being cut down at the merge.
  • Give ask_documents the same filters, so a model can ask a question of one file.