Skip to main content

docHandler4AI Python SDK

The docHandler4AI Python SDK provides a high-level, asynchronous interface to the docHandler4AI server. It enables advanced PDF processing, multimodal vision analysis, and robust vector indexing for both text and images.

Table of Contents


Model Parameters

The SDK provides typed schemas for model_params to help you configure specific AI models.

Global Parameters

Applies to most models (OpenAI, Gemini, etc.):

from dochandler4ai_sdk import GlobalModelParams

params = GlobalModelParams(temperature=0.7, max_tokens=1000)
result = await vision.describe(
    image_url="...",
    model_params=params
)

DeepSeek Specific Parameters

DeepSeek models support additional fields like "thinking" control:

from dochandler4ai_sdk import DeepSeekVisionParams

# Using the specialized schema
params = DeepSeekVisionParams(temperature=0.0, thinking={"type": "disabled"})

result = await vision.describe(
    image_url="...",
    model_name="deepseek-v4-flash-vision-exp",
    model_params=params
)

Installation

pip install docHandler4AISDK

Quick Start

Initialize the main client facade:

import asyncio
from dochandler4ai_sdk import DocHandler4AI

async def main():
    sdk = DocHandler4AI(
        base_url="http://localhost:8000",
        api_key="your_api_key"
    )
    
    # Use the SDK...
    
asyncio.run(main())

PDF Processing

Extract structured content from PDFs using Vision-based AI.

pdf_processor = sdk.get_pdf_process()

# 1. Process PDF to Markdown (optionally with chunks)
result = await pdf_processor.to_markdown(
    pdf_url="https://example.com/document.pdf",
    return_chunks=True
)
print(result["markdown"])

# 2. Process PDF directly to Chunks
result = await pdf_processor.to_chunks(
    pdf_url="https://example.com/document.pdf"
)
for chunk in result.get("chunks", []):
    print(chunk["content"])

Vision Analysis

Perform OCR, generate captions, or analyze specific PDF pages.

vision = sdk.get_vision_process()

# 1. Analyze image (Graph, Diagram, General content)
analysis = await vision.describe(
    image_url="https://example.com/diagram.png"
)
print(analysis["content"])

# 2. Extract text (OCR)
result = await vision.ocr(
    image_url="https://example.com/text_image.png"
)
print(result["content"])

# 3. PDF Page to Markdown
# Returns a single markdown with embedded image descriptions: 
# <image alt="" description="..."/>
result = await vision.to_markdown(
    image_url="https://example.com/pdf_page_render.png"
)
print(result["content"])

Document Indexing

Manage vector collections for text documents with metadata filtering.

The Importance of doc_id

When indexing documents, the doc_id is a unique identifier for a logical document (e.g., a specific PDF file).

  • Logical Grouping: A single PDF might be split into 50 chunks. All 50 chunks must share the same doc_id.
  • Automatic Updates: If you upsert chunks with a doc_id that already exists in the collection, the server will automatically replace the old chunks with the new ones. This ensures you don't have duplicate content for the same document.
  • Deletion: You can delete an entire document and all its associated chunks in one call using its doc_id.
from dochandler4ai_sdk import DocumentChunk

# Get document collection
docs = sdk.get_documents_collection(
    collection_id="my_docs",
    embedding_model="openai/text-embedding-3-small/1536" # Default for this collection
)

# Upsert documents
await docs.upsert(chunks=[
    DocumentChunk(
        doc_id="doc_001",
        page_content="Artificial Intelligence is transforming industries...",
        metadata={"category": "technology", "author": "Alice"}
    )
])

# Count documents
count = await docs.count(where={"category": "technology"})
print(f"Total technology documents: {count['total']}")

# Get sample documents
samples = await docs.get(k=5, where={"author": "Alice"})

Searching with Metadata Filters

The SDK supports complex metadata filtering using MongoDB-like operators ($or, $in, $gt, $lt, etc.).

from dochandler4ai_sdk import DocumentSearchRequest

req = DocumentSearchRequest(
    query="How is AI changing the world?",
    k=3,
    filters={
        "$or": [
            {"category": "technology"},
            {"tags": {"$in": ["AI", "ML"]}}
        ]
    }
)

results = await docs.search(req)

Self-Query Search

Let the LLM automatically translate natural language into structured filters.

req = DocumentSearchRequest(
    query="Show me documents by Alice about technology written after 2023",
    k=5,
    search_type="self_query",
    metadata_field_info=[
        {"name": "author", "description": "The author of the document", "type": "string"},
        {"name": "category", "description": "The document category", "type": "string"},
        {"name": "year", "description": "Year of publication", "type": "integer"}
    ]
)
results = await docs.search(req)

Image Indexing

Multi-modal vector storage for images.

from dochandler4ai_sdk import ImageItem

images = sdk.get_images_collection(
    collection_id="product_catalog",
    embedding_model="nvidia/llama-nemotron-embed-vl-1b-v2/2048"
)

# Upsert images
await images.upsert(images=[
    ImageItem(
        image_id="img_101",
        image_url="https://example.com/headphone.jpg",
        metadata={"category": "headphone", "brand": "Sony"}
    )
])

# Count images
count = await images.count(where={"category": "headphone"})

Multimodal Search

Search images using either a text query (Text-to-Image) or another image (Image-to-Image).

from dochandler4ai_sdk import ImageSearchRequest

# 1. Text-to-Image Search
req = ImageSearchRequest(
    query="blue wireless headphones",
    where={"brand": "Sony"},
    score_threshold=0.7
)
results = await images.search(req)

# 2. Image-to-Image Search
req = ImageSearchRequest(
    image_url="https://example.com/reference_image.jpg",
    k=5
)
results = await images.search(req)

Release files for docHandler4AISDK 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docHandler4AISDK 1.0.7
File Size Uploaded
dochandler4aisdk-1.0.7.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docHandler4AISDK 1.0.7
File Interpreter ABI Platform
dochandler4aisdk-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size:23.3 kB

Release files / dochandler4aisdk-1.0.7.tar.gz

Download URL dochandler4aisdk-1.0.7.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bd57b28bcf42870d376783ed81826daca24b994357b639657ea0ec6dbdc74ebe
BLAKE2b-256 checksum
How to use checksums
f9a02fd7fbd2a64295b60e0d2d2c3bbccb8441b4d27fbed283ba9d32456cfb57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / dochandler4aisdk-1.0.7-py3-none-any.whl

Download URL dochandler4aisdk-1.0.7-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
341c2d972f000d512e815de6235cbdd110b137413a0b0784499c3f50380bec6c
BLAKE2b-256 checksum
How to use checksums
f74127f39e2a27bdd60c42a2e53b1c147b8b8e3c56e22b71b065e1084088ea69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

1.0.9

2 release files

1.0.8

2 release files

This release

1.0.7 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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