Skip to content

Small-to-big retrieval

Small chunks match precisely, but they are often too short to answer from. Large chunks have the context, but their embeddings blur several topics together. Small-to-big keeps both: documents chunked with parent_chunk_size are searched by their small chunks, and each match returns its parent.

flowchart LR
    subgraph Parent["parent 4 (≈1500 chars)"]
        C1["chunk 16"]
        C2["chunk 17 ✓"]
        C3["chunk 18 ✓"]
        C4["chunk 19"]
    end
    Q["query"] -. matches .-> C2
    Q -. matches .-> C3
    Parent --> R["one result:<br/>parent 4's text,<br/>score of chunk 17"]

Turn it on

# Per upload
curl -X POST localhost:8000/api/v1/projects/1/documents \
     -F files=@handbook.pdf -F chunk_size=300 -F parent_chunk_size=1500

# For a project
curl -X PATCH localhost:8000/api/v1/projects/1 -H 'Content-Type: application/json' \
     -d '{"chunking": {"chunk_size": 300, "parent_chunk_size": 1500}}'

Or set PARENT_CHUNK_SIZE as the server default. parent_chunk_size must be larger than chunk_size, in the same unit; 0 turns parents off. Existing documents get parents when they are re-processed.

How parents are built

  • A parent is a run of consecutive chunks, up to parent_chunk_size.
  • Once it is at least half full, a parent also ends where the section (headings, titles) changes. It always ends at a new sheet or table.
  • A chunk larger than the size is a parent of its own.
  • The parent text is the document text from its first chunk to its last, with overlaps kept once. Re-rendered chunks (tables, JSON) are joined with blank lines.
  • Parent metadata combines the chunks' locations (page, row and time ranges, titles, shared headings) and adds chunk_start / chunk_end.

Parents are stored in Postgres only; they are not embedded.

How searching works

  1. The chunks are scored as usual, and score_threshold is applied to their scores.
  2. Chunks of the same parent become one result, scored by its best chunk.
  3. dedupe, the reranker (which scores the parent text), diversity and top_k then work on parents.

Results

Field
text, metadata, citation The parent's
parent_id, parent_index The parent
chunk_id, chunk_index Its best chunk
matches Every matching chunk of the parent (id, index, score, text, metadata), best first

stats.parent_merged counts the chunks merged into a better one of the same parent.

  • neighbors extends the parent: context runs from neighbors chunks before its first chunk to neighbors after its last.
  • return_parents: false returns the chunks themselves.
  • Documents chunked without parents return their chunks, so projects can mix both.

Inspect

curl localhost:8000/api/v1/projects/1/documents/7/parents
curl -X POST localhost:8000/api/v1/projects/1/documents/7/preview -H 'Content-Type: application/json' \
     -d '{"chunking": {"chunk_size": 300, "parent_chunk_size": 1500}}'

The preview shows parent_count, parent_chars and the parents.

Choosing sizes

A common start is chunks of 200-400 characters with parents of 1200-2000. In evaluation, a parent passage counts as relevant for every chunk it covers, so compare return_parents: true and false on the same questions to see what your LLM gets.