Document Classification Pipeline
Classify documents into custom business categories using layout-aware extraction and taxonomy enrichment. Handles invoices, contracts, reports, forms, and correspondence by analyzing both textual content and visual document structure.
import requestsfrom mixpeek import Mixpeekclient = Mixpeek(api_key="YOUR_API_KEY", namespace="documents")API = "https://api.mixpeek.com/v1"HEADERS = {"Authorization": "Bearer YOUR_API_KEY", "X-Namespace": "documents"}# 1. Exemplars: sample invoices, contracts, reports, forms and lettersexample_bucket = client.buckets.create(bucket_name="document-examples",bucket_schema={"properties": {"document": {"type": "pdf"}}},)examples = client.collections.create(collection_name="document-examples",source={"type": "bucket", "bucket_ids": [example_bucket["bucket_id"]]},feature_extractor={"feature_extractor_name": "document_graph_extractor","version": "v1",},)client.buckets.upload(example_bucket["bucket_id"],blobs=[{"property": "document", "type": "pdf", "data": "s3://your-bucket/examples/invoice-01.pdf"}],)client.collections.trigger(examples["collection_id"])# 2. The retriever the taxonomy uses to find the closest exemplar blockmatcher = client.retrievers.create(retriever_name="document-type-matcher",collection_identifiers=["document-examples"],input_schema={"query": {"type": "text", "required": True}},stages=[{"stage_name": "search","stage_id": "feature_search","parameters": {"searches": [{"feature_uri": "mixpeek://document_graph_extractor@v1/intfloat__multilingual_e5_large_instruct","query": {"input_mode": "text", "value": "{{INPUT.query}}"},"top_k": 3,},],"final_top_k": 3,},},],)# A flat taxonomy matches each document, through a retriever, against a# collection of labeled examples. The SDK has no taxonomies resource, so this is REST.taxonomy = requests.post(API + "/taxonomies", headers=HEADERS, json={"taxonomy_name": "document_types","config": {"taxonomy_type": "flat","retriever_id": matcher["retriever_id"],"input_mappings": [{"input_key": "query", "source_type": "payload", "path": "text_raw"}],"source_collection": {"collection_id": examples["collection_id"]},},}).json()# 3. Incoming documents are labeled as they are writtenbucket = client.buckets.create(bucket_name="incoming",bucket_schema={"properties": {"document": {"type": "pdf"}}},)incoming = client.collections.create(collection_name="incoming-documents",source={"type": "bucket", "bucket_ids": [bucket["bucket_id"]]},feature_extractor={"feature_extractor_name": "document_graph_extractor","version": "v1",},taxonomy_applications=[{"taxonomy_id": taxonomy["taxonomy_id"], "execution_mode": "materialize"}],)client.buckets.upload(bucket["bucket_id"],blobs=[{"property": "document", "type": "pdf", "data": "s3://your-bucket/incoming/scan-2291.pdf"}],)client.collections.trigger(incoming["collection_id"])# 4. An LLM check for blocks whose label needs a second lookreview = client.retrievers.create(retriever_name="classification-review",collection_identifiers=["incoming-documents"],input_schema={"query": {"type": "text", "required": True}},stages=[{"stage_name": "search","stage_id": "feature_search","parameters": {"searches": [{"feature_uri": "mixpeek://document_graph_extractor@v1/intfloat__multilingual_e5_large_instruct","query": {"input_mode": "text", "value": "{{INPUT.query}}"},"top_k": 50,},],"final_top_k": 50,},},{"stage_name": "validate", "stage_id": "llm_filter", "parameters": {"criteria": "Keep blocks that read like an invoice: line items, totals and a due date.", "provider": "google", "model_name": "gemini-2.5-flash-lite"}},],)results = client.retrievers.execute(review["retriever_id"], inputs={"query": "amount due and payment terms"})print(len(results["documents"]), "invoice-like blocks")
Feature Extractors
Document Graph Extractor
Decompose PDFs into spatial blocks (paragraphs, tables, forms, headers) with layout classification and E5 text embeddings.
Retriever Stages
feature search
Search and filter documents by vector similarity using feature embeddings
taxonomy enrich
Classify documents against taxonomy nodes via vector similarity
llm filter
Filter documents using LLM-based semantic evaluation
Use Cases Using This Recipe
Clinical NLP at Scale
Extract structured intelligence from clinical notes, pathology reports, and medical records
94% F1 on medical NER benchmarks
Entity extraction accuracy
Healthcare IT teams, clinical informatics departments, and health systems processing thousands of clinical documents daily
Related Recipes & Resources
Explore these related resources to deepen your understanding and discover more powerful features
Document Graph Extractor
Decompose PDFs into spatial blocks (paragraphs, tables, forms, headers) with layout classification and E5 text embeddings.
Multimodal Content Moderation
Automated content moderation pipeline that analyzes text, images, and video for policy violations. Uses hierarchical taxonomy classification to label content as safe, sensitive, or prohibited across multiple categories simultaneously.
Document Intelligence Search
Extract and search through PDFs, presentations, and documents. Combines OCR, layout analysis, and semantic search for comprehensive document retrieval.
PDF Data Extraction Pipeline
Extract structured data from PDFs including tables, forms, and text. Convert unstructured documents into structured, queryable data.
Document RAG Pipeline
Retrieval-augmented generation for document collections. Extracts text, tables, and figures from PDFs using OCR and layout analysis, then retrieves relevant page sections to answer natural language questions with precise page and section citations.
BYO Embeddings Vector Search
Bring pre-computed embeddings from any provider (OpenAI, Cohere, Together, etc.) and upsert them directly into MVS for instant vector search. No feature extractors, no pipelines -- just embeddings in, results out.