Skip to content

API Reference parrot.stores.utils.chunking

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.stores.utils.chunking

View source

Class ChunkInfo

Information about a document chunk

Parameter Type Default Description
chunk_id str
parent_document_id str
chunk_index int
chunk_text str
start_position int
end_position int
chunk_embedding np.ndarray
metadata Dict[str, Any]

Fields:

Field Type Default Description
chunk_id str
parent_document_id str
chunk_index int
chunk_text str
start_position int
end_position int
chunk_embedding np.ndarray
metadata Dict[str, Any]

Alias Document

Re-exported from parrot.stores.models.Document.

Class LateChunkingProcessor

Late Chunking processor integrated with PgVectorStore.

Late chunking generates embeddings for the full document first, then creates contextually-aware chunk embeddings that preserve the global document context.

Parameter Type Default Description
vector_store
chunk_size int 8192
chunk_overlap int 200
preserve_sentences bool True
min_chunk_size int 100

Method LateChunkingProcessor.process_document_late_chunking

Process document with late chunking strategy.

process_document_late_chunking(document_text: str, document_id: str, metadata: Optional[Dict[str, Any]] = None) -> Tuple[np.ndarray, List[ChunkInfo]]

Parameter Type Default Description
document_text str Full document text
document_id str Unique document identifier
metadata Optional[Dict[str, Any]] None Optional metadata for the document

Returns: Tuple[np.ndarray, List[ChunkInfo]] — Tuple of (full_document_embedding, list_of_chunk_info)

Method LateChunkingProcessor.process_document_three_level

Split an oversized document into the 3-level hierarchy.

Architecture:

  • Level 1: original document (NOT stored as a parent row)
  • Level 2: parent_chunks (~parent_chunk_size_tokens chars each)
  • Level 3: child chunks (via existing late-chunking per parent_chunk)

Each child's parent_document_id points to its parent_chunk UUID, NOT to the original document. The original document is never returned as a parent (it is too large for the LLM context).

process_document_three_level(document_text: str, document_id: str, metadata: Optional[Dict[str, Any]] = None, parent_chunk_size_tokens: int = 4000, parent_chunk_overlap_tokens: int = 200) -> Tuple[List[Document], List[ChunkInfo]]

Parameter Type Default Description
document_text str Full document text.
document_id str Original document ID (stored as source_document_id on parent_chunks for audit).
metadata Optional[Dict[str, Any]] None Optional base metadata inherited by parent_chunks.
parent_chunk_size_tokens int 4000 Target parent chunk size in characters (the "token" unit in this code base is characters).
parent_chunk_overlap_tokens int 200 Overlap between adjacent parent chunks in characters. Must be < parent_chunk_size_tokens.

Returns: Tuple[List[Document], List[ChunkInfo]] — Tuple of (parent_chunk_documents, child_chunk_infos) where: - parent_chunk_documents: list of :class:Document objects with metadata['document_type'] == 'parent_chunk', metadata['is_chunk'] == False, metadata['source_document_id'] == document_id. - child_chunk_infos: list of :class:ChunkInfo whose parent_document_id points to a parent_chunk UUID.

Raises:

  • ValueError — If parent_chunk_overlap_tokens >= parent_chunk_size_tokens.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally