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
Installation
pip install docHandler4AI-sdk
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()
# Process PDF to Markdown with chunks
result = await pdf_processor.process(
pdf_url="https://example.com/document.pdf",
response_output="markdown",
return_chunks=True
)
print(result["markdown"])
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()
# Analyze image (OCR, caption, or pdf_page)
analysis = await vision.analyze(
image_url="https://example.com/image.png",
type="caption"
)
print(analysis["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_idthat 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)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dochandler4aisdk-1.0.1.tar.gz.
File metadata
- Download URL: dochandler4aisdk-1.0.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89c0047f0090d56bd5fbf5601cc29f30d4cd513f692b10ec90a17eff3801a5f7
|
|
| MD5 |
36d396aca645ff265bd39c43939dffd5
|
|
| BLAKE2b-256 |
cd9f8fa1f26c976a2f86a7a2ccd6090a169b7fb23b0879e4bc2bf518481a4ef9
|
File details
Details for the file dochandler4aisdk-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dochandler4aisdk-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2db8f579322e3c173fa3a7db87e507a6c4205ab921be5d631d923ab679752da9
|
|
| MD5 |
807afcbfc20af31d981395dfa6bafcab
|
|
| BLAKE2b-256 |
202ae016ee3e8c0290092a8bc4b02d0cf3b021c3ecf35e2356bd021a85aa4d0f
|