Skip to main content
Turn a document into retrieval-ready chunks, embed them, and keep the metadata that ties each answer to its file and pages.

What you need

  • The Python SDK and an API key, set up as in Cookbooks.
  • LangChain and an embedding model: pip install langchain-core langchain-huggingface sentence-transformers.
  • A document to index. This recipe uses the Attention Is All You Need sample, which has 15 pages.

Build it

1

Parse with semantic chunking

This call parses the paper with semantic chunking and reads the result once the parse finishes. Choose a chunk size explains max_characters.
If chunking can’t finish, the parse still completes, with an empty chunk list and a CHUNKS_SKIPPED warning.
2

Turn chunks into documents

This code makes one LangChain document per chunk. The metadata holds what you filter on at query time (tenant_id) and what you cite (file_name and pages).
A chunk’s id is its place in reading order, such as semantic-0. Its content is Markdown, with page breaks and figure images removed.
3

Embed and index

This code embeds every chunk into an in-memory vector store. Any LangChain embedding model and vector store take the same documents.
4

Search with provenance

This code searches one tenant’s chunks and prints the file and pages of each hit.
Filter by tenant before any chunk reaches a model. Pass each hit to the model with its file name and pages, so the answer can cite them.

How it works

This diagram shows where each part of a chunk goes in the vector store: At query time, the metadata does the work: The vector id combines the parse_id and the chunk’s id, so indexing the same parse again reuses its ids, and a store that writes by id, such as InMemoryVectorStore, replaces those vectors instead of adding copies.

Choose a chunk size

A chunk longer than max_characters is cut again, at paragraph breaks first, then at line, sentence and word breaks. Chunking is included in Parse’s price.

Keep the index current

A new parse of a document has a new parse_id and new chunk boundaries. Delete the document’s old vectors by document_id, then index the new ones.
Read each result once, and keep it before you index it. A result can expire, and some organizations delete a result the first time it’s read.
To index one chunk per page instead, join each page’s elements and leave out page headers, footers and numbers:

Next steps

Parse options

Chunking, word boxes, footnotes and more.

Elements and bounding boxes

Element categories, pages and boxes.