NEWVectors or files. Pick a path.Start →

    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.

    text
    image
    Multi-Stage
    import requests
    from mixpeek import Mixpeek
    client = 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 letters
    example_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 block
    matcher = 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 written
    bucket = 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 look
    review = 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

    filter

    taxonomy enrich

    Classify documents against taxonomy nodes via vector similarity

    apply

    llm filter

    Filter documents using LLM-based semantic evaluation

    filter

    Use Cases Using This Recipe

    Advanced
    12 min

    Clinical NLP at Scale

    Extract structured intelligence from clinical notes, pathology reports, and medical records

    94% F1 on medical NER benchmarks

    Entity extraction accuracy

    Who It's For

    Healthcare IT teams, clinical informatics departments, and health systems processing thousands of clinical documents daily