Skip to main content

fpf-chunking

FPF-guided (holon / bounded-context) semantic document chunking: parses a document's structure, uses an LLM to validate which structural boundaries make good chunk boundaries, and assembles the result into token-bounded chunks — without ever exceeding the LLM's context window on a single oversized structural unit.

Install

pip install fpf-chunking

Add [gemini] if you want to use Gemini (pip install fpf-chunking[gemini]) — Anthropic and OpenAI support is included in the base install.

Usage

Boundary validation and embeddings each take a small adapter that wraps your provider's real SDK client — see fpf_chunking.adapters for AnthropicAdapter, OpenAIAdapter, and GeminiAdapter. Mix and match providers freely; nothing in the pipeline is tied to a specific one.

From a file, using Anthropic for boundary validation and OpenAI for embeddings:

from anthropic import Anthropic
from openai import OpenAI
from fpf_chunking import MarkdownLoader, chunk_document, embed
from fpf_chunking.adapters import AnthropicAdapter, OpenAIAdapter

doc = MarkdownLoader().load("path/to/doc.md")

completion_client = AnthropicAdapter(
    Anthropic(api_key="..."), model="claude-sonnet-4-5-20250929"
)
chunks = chunk_document(doc, completion_client=completion_client, max_chunk_tokens=400)

embedding_client = OpenAIAdapter(OpenAI(api_key="..."), model="text-embedding-3-small")
embedded = embed(chunks, client=embedding_client)

From content already in memory (e.g. fetched over the network by your own wrapper — no filesystem path required):

from fpf_chunking import Document, chunk_document

doc = Document(doc_id="my-doc", text=buffer_from_network)
chunks = chunk_document(doc, completion_client=completion_client, max_chunk_tokens=400)

Or run the whole pipeline on Gemini, sharing one client across both roles:

from google import genai
from fpf_chunking import chunk_document, embed
from fpf_chunking.adapters import GeminiAdapter

client = genai.Client(api_key="...")
completion_client = GeminiAdapter(client, model="gemini-2.5-flash")
embedding_client = GeminiAdapter(client, model="gemini-embedding-001")

chunks = chunk_document(doc, completion_client=completion_client, max_chunk_tokens=400)
embedded = embed(chunks, client=embedding_client)

See the module docstrings for the full API: parse_holons, extract_candidate_boundaries, split_oversized_holons, assemble_chunks, FPFBoundaryValidator, fixed_size_chunks (naive baseline), and semantic_chunks (embedding-similarity baseline) are all exported for callers who want the individual pipeline stages instead of the composed chunk_document. CompletionClient/EmbeddingClient (also exported) are the two protocols every adapter implements, if you want to write your own for another provider.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fpf_chunking-0.2.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fpf_chunking-0.2.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file fpf_chunking-0.2.1.tar.gz.

File metadata

  • Download URL: fpf_chunking-0.2.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fpf_chunking-0.2.1.tar.gz
Algorithm Hash digest
SHA256 485e462f7c88350caa68d49835cab85099f81691bdb14d0ccc658431ea83d1c3
MD5 c8082f295b7bbac6e105e40e37a91c32
BLAKE2b-256 969376edeedd686a02f97f60b818df0c4c76cc9c0c97a61bb2584aeafc73f564

See more details on using hashes here.

File details

Details for the file fpf_chunking-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fpf_chunking-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fpf_chunking-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f49319a6fc09e4b3edac1e91bb9871c12d440628e17b3864c5ba6fd0b9e7143e
MD5 f9bfc4c4168326f54dd344182768b7ab
BLAKE2b-256 386dd5e67cd2deb3da81870d28ab85d04e723bdbe1b516a33d2bfa097e89e970

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page