Kafka
Stream document chunks to Apache Kafka topics
Kafka Connector
The Kafka connector streams document chunks to Apache Kafka topics as individual messages. This connector is target-only and chunks-only - only produces chunked output suitable for downstream processing.
Prerequisites
- Kafka Cluster: Access to an Apache Kafka cluster (self-hosted, Confluent Cloud, AWS MSK, etc.)
- Kafka Topic: A topic to publish chunks to
- Bootstrap Servers: Kafka broker addresses
- Authentication (if required): SASL credentials and potentially CA Cert for secure clusters
Setup and Authentication
Kafka Cluster Access
Ensure you have:
- Bootstrap server addresses (e.g.,
broker1:9092,broker2:9092) - Topic name where chunks will be published
- Authentication credentials (if your cluster requires SASL)
Authentication Methods
SASL Authentication
For production clusters (Confluent Cloud, secure on-premise):
- Supported mechanisms:
PLAIN,SCRAM-SHA-256,SCRAM-SHA-512 - Provide username and password
- Uses
SASL_SSLby default (TLS + SASL)
Custom CA Certificate
If your cluster uses a self-signed or internal CA certificate:
- Obtain the CA certificate file (
.crtor.pem) - Base64-encode it:
cat your_ca.crt | base64 | tr -d '\n' - Include the encoded string in the
ca_certfield of yourauthconfiguration
Configuration
The Kafka connector is used as a target in the Batch API.
Required Parameters
| Parameter | Type | Description |
|---|---|---|
kind | string | Must be "kafka_chunks" |
bootstrap_servers | array | List of Kafka broker addresses (e.g., ["broker1:9092", "broker2:9092"]) |
topic | string | Kafka topic to publish chunks to |
Optional Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
auth | object | null | SASL authentication configuration. Omit for plaintext (no auth) |
security_protocol | string | Auto | Connection protocol. Auto-selects SASL_SSL when auth is set, PLAINTEXT otherwise. Options: PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL |
verify_certs | boolean | true | Verify broker TLS certificates. Only applies to SSL/SASL_SSL protocols |
key_mode | string | "doc_id" | Message key strategy. Options: doc_id (all chunks of a document in one partition), chunk_id (spread across partitions), none (null key, round-robin) |
acks | string | "all" | Producer acknowledgment mode. Options: 0 (no ack), 1 (leader only), all (all replicas) |
compression_type | string | "lz4" | Producer compression. Options: none, gzip, snappy, lz4, zstd |
queue_max_kbytes | integer | 65536 | Producer queue size limit in KiB |
queue_max_messages | integer | 10000 | Producer queue size limit in message count |
text_field | string | "text" | Field name for chunk text in message value |
metadata_field | string | "metadata" | Field name for chunk metadata |
doc_id_field | string | "doc_id" | Field name for source document identifier |
chunk_index_field | string | "chunk_index" | Field name for chunk position in document |
chunk_id_field | string | "chunk_id" | Field name for deterministic chunk ID (used for deduplication) |
page_field | string | "page_numbers" | Field name for page numbers |
headings_field | string | "headings" | Field name for chunk headings |
coerce_large_ints_to_str | boolean | false | Convert large integers to strings |
SASL Auth Object
When providing auth, include these fields:
| Field | Type | Default | Description |
|---|---|---|---|
kind | string | "sasl" | Must be "sasl" |
mechanism | string | "PLAIN" | SASL mechanism. Options: PLAIN, SCRAM-SHA-256, SCRAM-SHA-512 |
username | string | - | SASL username |
password | string | - | SASL password |
ca_cert | string | - | Base64-encoded CA certificate for self-signed/internal CAs |
Connector-Specific Behavior
Message Structure
Each chunk is published as a separate Kafka message with:
- Key: Based on
key_mode(doc_id, chunk_id, or null) - Value: JSON object containing chunk text and metadata
- Headers: Include
chunk_idfor deduplication
Example message value:
{
"text": "This is the chunk text content...",
"metadata": {
"source": "document.pdf",
"page": 1
},
"doc_id": "abc123",
"chunk_index": 0,
"chunk_id": "def456",
"page_numbers": [1],
"headings": ["Introduction"]
}Key Modes
doc_id (default, recommended):
- All chunks of a document go to the same partition
- Ordered delivery within a document (requires
acks: "all") - Warning: Do NOT enable log compaction with this mode - it would keep only the last chunk per document
chunk_id:
- Content-addressed stable hash
- Chunks spread across partitions for parallelism
- No ordering guarantee
none:
- Null key, round-robin distribution
- No ordering, maximum throughput
Acknowledgment Modes
all (default, most durable):
- Wait for all in-sync replicas
- Enables idempotent producer (prevents duplicates on retry)
- Required for ordered delivery with
key_mode: doc_id
1 (leader ack):
- Wait for leader replica only
- Faster but less durable
0 (fire-and-forget):
- No acknowledgment
- Fastest but may lose messages
Chunking
Documents are automatically chunked using Docling's chunking engine. Control chunking behavior with options.chunking_options in your batch request.
Note that this field is optional. Docling will choose a default tokenizer for you - it just may not align with downstream processing.
{
"options": {
"chunking_options": {
"chunker": "hybrid",
"tokenizer": "sentence-transformers/all-MiniLM-L6-v2",
"max_tokens": 512
}
}
}Security and Permissions
Kafka ACLs
Your SASL user needs permissions for:
- WRITE on the target topic
- CREATE on the topic (if it doesn't exist and broker allows auto-creation)
TLS/SSL
For secure clusters:
- Use
SASL_SSLorSSLprotocol - Broker certificates must be valid or
ca_certmust be provided - Set
verify_certs: falseonly for development with self-signed certs
Limitations
- Target Only: Kafka connector cannot read documents (source mode not supported)
- Chunks Only: Only publishes chunked output, not full documents
- Message Size: Kafka has a default max message size of 1 MB. Ensure
max_tokensin chunking options produces chunks within this limit - Ordering: Only guaranteed within a partition when using
key_mode: doc_idwithacks: all - No Transaction Support: Messages are published independently, not in Kafka transactions
- Log Compaction Warning: Do not enable log compaction with
key_mode: doc_id- it would silently discard all but the last chunk
Usage Examples
There are three main ways to interface with the connectors. All use the same underlying POST /v1/convert/source/batch endpoint.
Tasks UI
Navigate to the Tasks view and select "Create Task +". Select Batch as the task type (connectors use batch tasks, not single).
Fill in the fields as prompted. They should correspond to the fields gathered above (excluding 'kind').
Screenshots for this connector will be added here.
REST API
curl -X POST "${DOCLING_SERVICE_URL}/v1/convert/source/batch" \
-H "X-Api-Key: ${DOCLING_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"sources": [
{
"kind": "s3",
"endpoint": "s3.us-east-1.amazonaws.com",
"access_key": "YOUR_ACCESS_KEY",
"secret_key": "YOUR_SECRET_KEY",
"bucket": "my-documents",
"key_prefix": "pdfs/"
}
],
"target": {
"kind": "kafka_chunks",
"bootstrap_servers": ["broker1.example.com:9092", "broker2.example.com:9092"],
"topic": "docling.chunks",
"key_mode": "doc_id",
"auth": {
"kind": "sasl",
"mechanism": "PLAIN",
"username": "your-username",
"password": "your-password"
},
"acks": "all",
"compression_type": "lz4"
},
"options": {
"to_formats": ["json"],
"chunking_options": {
"chunker": "hybrid",
"tokenizer": "sentence-transformers/all-MiniLM-L6-v2",
"max_tokens": 512
}
}
}'With Custom CA Certificate
curl -X POST "${DOCLING_SERVICE_URL}/v1/convert/source/batch" \
-H "X-Api-Key: ${DOCLING_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"sources": [
{
"kind": "http",
"url": "https://example.com/document.pdf"
}
],
"target": {
"kind": "kafka_chunks",
"bootstrap_servers": ["internal-broker.corp:9092"],
"topic": "docling.chunks",
"auth": {
"kind": "sasl",
"mechanism": "PLAIN",
"username": "your-username",
"password": "your-password",
"ca_cert": "xXx...BASE64_ENCODED_CERT...xXx"
}
},
"options": {
"chunking_options": {
"chunker": "hybrid",
"max_tokens": 512
}
}
}'Python SDK
Python SDK Note: This connector is not included in the standard docling.datamodel.service package. When using the Python SDK, configure it using GenericTargetRequest with keyword arguments. You do not need to install docling-jobkit.
from docling.service_client import DoclingServiceClient
from docling.datamodel.service.requests import S3SourceRequest
from docling.datamodel.service.targets import GenericTargetRequest
import os
SERVICE_URL = os.getenv("DOCLING_SERVICE_URL")
API_KEY = os.getenv("DOCLING_API_KEY")
# Kafka target with SASL authentication
target = GenericTargetRequest(
kind="kafka_chunks",
bootstrap_servers=["broker1.example.com:9092", "broker2.example.com:9092"],
topic="docling.chunks",
key_mode="doc_id",
auth={
"kind": "sasl",
"mechanism": "PLAIN",
"username": "your-username",
"password": "your-password"
},
acks="all",
compression_type="lz4"
)
with DoclingServiceClient(url=SERVICE_URL, api_key=API_KEY) as client:
job = client.submit_batch(
sources=[
S3SourceRequest(
endpoint="s3.us-east-1.amazonaws.com",
access_key="YOUR_ACCESS_KEY",
secret_key="YOUR_SECRET_KEY",
bucket="my-documents",
key_prefix="pdfs/"
)
],
target=target,
output_formats=["json"],
chunking_options={
"chunker": "hybrid",
"tokenizer": "sentence-transformers/all-MiniLM-L6-v2",
"max_tokens": 512
}
)
# Wait for completion
response = job.result()
print(f"Processed {response.num_converted} documents")
print(f"Succeeded: {response.num_succeeded}")
print(f"Failed: {response.num_failed}")Related Documentation
- Batch API Reference - Complete batch endpoint documentation
- Connectors Overview - All available connectors
- Apache Kafka Documentation - Official Kafka documentation
- Confluent Cloud - Managed Kafka service documentation