Apache Tika
Pull text and metadata out of PDFs, Office files and other documents, detect their type and language, and OCR scanned images
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/tika/index.md to help me query Apache Tika with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Extract text and metadata from a PDF
Uses a public sample PDF. Replace its URL with a local file path to read your own document.
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SET VARIABLE pdf = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/v0.4.2/test/sql/data/multipage.pdf'));
SELECT content, mime, n_pages FROM tika.main.extract_text(getvariable('pdf'));
| content | mime | n_pages |
|---|---|---|
| First page alpha content. Second page beta content. Third page gamma con… | application/pdf | 3 |
Quick start
Choose where to run Apache Tika, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tika' AS tika (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-tika:0.5.0'
);
3. Run a query
SET VARIABLE pdf = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/v0.4.2/test/sql/data/multipage.pdf'));
SELECT content, mime, n_pages FROM tika.main.extract_text(getvariable('pdf'));
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'tika' AS tika
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SET VARIABLE pdf = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/v0.4.2/test/sql/data/multipage.pdf'));
SELECT content, mime, n_pages FROM tika.main.extract_text(getvariable('pdf'));
Query Farm operates Apache Tika for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use tika as the catalog alias for the query below.
4. Run a query
SET VARIABLE pdf = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/v0.4.2/test/sql/data/multipage.pdf'));
SELECT content, mime, n_pages FROM tika.main.extract_text(getvariable('pdf'));
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tika' AS tika (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-tika:0.5.0'
);
Overview
Document text, metadata, and OCR extraction (Apache Tika)
Extract plain text, document metadata, language, page counts, and OCR directly in DuckDB SQL from PDF, Word, Excel, PowerPoint, HTML, email, and image files — powered by Apache Tika (source).
What it does
The tika extension turns DuckDB into a document-parsing engine: point it at a file path or a BLOB of document bytes and get back searchable plain text plus a rich metadata map, all without leaving SQL. It is built for data engineers, analysts, and AI/RAG pipelines that need to mine unstructured documents — contracts, invoices, reports, slide decks, spreadsheets, web pages, and scanned images — and join the extracted content against the rest of their warehouse. Because it runs as a VGI worker over Apache Arrow, extraction happens close to your data with no external service calls and no manual file shuffling.
How it works
Every function is backed by Apache Tika, the battle-tested Apache content-detection and analysis toolkit that ships more than a thousand parsers (PDFBox for PDF, Apache POI for Microsoft Office, and many more). Tika auto-detects each document's media type and dispatches it to the right parser, so a single call handles dozens of formats. Scanned PDFs and images are run through Tesseract OCR when the Tesseract binary is available; when it is not, OCR results return NULL rather than failing the query. See the official Apache Tika documentation for the full parser and metadata catalog.
When to use it
Reach for this worker whenever unstructured documents need to become queryable rows: building a full-text or vector index over a document store, routing or filtering files by their true media type, detecting the language of a body of text, or pulling structured metadata (author, title, creation date, page count) out of office and PDF files. Inputs are always either a VARCHAR filesystem path the worker opens or a BLOB of the raw document bytes, so documents already living in a table column can be processed in place without shuffling files around.
Navigating the functions
The worker's functions are organized into navigable categories — text and metadata extraction (single-document and whole-column batch), content detection (media type and language), and optical character recognition — each carrying its own runnable examples and documented return columns.
Catalog
Everything tika exposes once attached — read straight from the worker's
released build.
main 7 functions
Apache Tika document text, metadata, and OCR extraction functions.
Schema examples (7)
Extract the plain-text body and detected media type from a single document.
SELECT content, mime
FROM tika.main.extract_text('A plain-text body.'::BLOB);
Read a document's media type and page count without extracting its body text.
SELECT mime, n_pages FROM tika.main.metadata('Some document bytes.'::BLOB);
Detect the media (MIME) type of a document from its raw bytes.
SELECT tika.main.detect_mime('Plain text.'::BLOB);
Detect the natural-language code of a body of text.
SELECT tika.main.detect_lang('The quick brown fox jumps over the lazy dog.');
3 more examples
Batch-extract a whole column of documents, passing an id column through onto every output row.
SELECT id, content
FROM tika.main.extract_all((SELECT * FROM (VALUES (1, 'Body bytes.'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body');
Language breakdown of a document corpus: extract every body with extract_all, tag it with detect_lang, and send bodies whose detect_lang_conf is below 0.5 (or undetectable) to 'und'. Returns en [1, 4] and und [5, 6] (2 docs each), then de [3] and fr [2].
SELECT CASE WHEN tika.main.detect_lang_conf(content) >= 0.5 THEN tika.main.detect_lang(content) ELSE 'und' END AS language,
count(*) AS docs, list(id ORDER BY id) AS ids
FROM tika.main.extract_all((SELECT id, body FROM (VALUES (1, 'The quarterly report shows strong growth across every region this year.'::BLOB), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les regions.'::BLOB), (3, 'Der Quartalsbericht zeigt ein starkes Wachstum in allen Regionen.'::BLOB), (4, 'Our customers renewed their contracts early and expanded their usage.'::BLOB), (5, 'OK'::BLOB), (6, 'PO-88213'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body')
GROUP BY language
ORDER BY docs DESC, language;
Triage a mixed inbox of raw bytes: detect_mime sniffs each blob so only the HTML pages go through extract_all (the PNG, id 2, is skipped), then each page's <title> is read from the metadata map and its body language tagged with detect_lang (1 'Q3 Update' en, 3 'Point trimestriel' fr).
WITH inbox(id, body) AS (VALUES (1, '<html><head><title>Q3 Update</title></head><body><p>Revenue grew in every region this quarter and margins improved.</p></body></html>'::BLOB), (2, '\x89PNG\x0D\x0A\x1A\x0A\x00\x00\x00\x0DIHDR'::BLOB), (3, '<html><head><title>Point trimestriel</title></head><body><p>Le chiffre d''affaires a progresse dans toutes les regions ce trimestre.</p></body></html>'::BLOB)) SELECT x.id, x.meta['dc:title'] AS title, tika.main.detect_lang(x.content) AS language
FROM tika.main.extract_all((SELECT id, body FROM inbox WHERE tika.main.detect_mime(body) = 'text/html'), id := 'id', doc_column := 'body') AS x
ORDER BY x.id;
detect_lang (text VARCHAR)
Detect the ISO-639 language code of a piece of text (Apache Tika language detection).
Detect the ISO-639 language code of a piece of text (returns 'en' here).
SELECT tika.main.detect_lang('The quick brown fox jumps over the lazy dog.');
Detect the language of an extracted document's body text.
SELECT content, tika.main.detect_lang(content) AS lang
FROM tika.main.extract_text('Bonjour le monde, ceci est un texte en francais.'::BLOB);
detect_lang_conf (text VARCHAR)
Confidence (0.0-1.0) of the top detected language for a piece of text (Apache Tika language detection); the companion score to detect_lang.
Confidence (0.0-1.0) of the top detected language for a piece of text.
SELECT tika.main.detect_lang_conf('The quick brown fox jumps over the lazy dog.');
Report the detected language and its confidence for an extracted document body.
SELECT tika.main.detect_lang(content) AS lang,
tika.main.detect_lang_conf(content) AS conf
FROM tika.main.extract_text('The annual report covers quarterly results.'::BLOB);
Language breakdown of a document corpus: extract every body with extract_all, tag it with detect_lang, and send bodies whose detect_lang_conf is below 0.5 (or undetectable) to 'und'. Returns en [1, 4] and und [5, 6] (2 docs each), then de [3] and fr [2].
SELECT CASE WHEN tika.main.detect_lang_conf(content) >= 0.5 THEN tika.main.detect_lang(content) ELSE 'und' END AS language,
count(*) AS docs, list(id ORDER BY id) AS ids
FROM tika.main.extract_all((SELECT id, body FROM (VALUES (1, 'The quarterly report shows strong growth across every region this year.'::BLOB), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les regions.'::BLOB), (3, 'Der Quartalsbericht zeigt ein starkes Wachstum in allen Regionen.'::BLOB), (4, 'Our customers renewed their contracts early and expanded their usage.'::BLOB), (5, 'OK'::BLOB), (6, 'PO-88213'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body')
GROUP BY language
ORDER BY docs DESC, language;
detect_mime (doc ANY)
Detect a document's MIME type from its bytes or a file path (Apache Tika).
Detect the MIME type of inline document bytes (returns 'text/plain').
SELECT tika.main.detect_mime('Hello, plain text body.'::BLOB);
Detect the MIME type of a PDF read as bytes with read_blob() (returns 'application/pdf'); a local file path works the same.
SELECT tika.main.detect_mime(content)
FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/v0.4.0/test/sql/data/hello.pdf');
Triage a mixed inbox of raw bytes: detect_mime sniffs each blob so only the HTML pages go through extract_all (the PNG, id 2, is skipped), then each page's <title> is read from the metadata map and its body language tagged with detect_lang (1 'Q3 Update' en, 3 'Point trimestriel' fr).
WITH inbox(id, body) AS (VALUES (1, '<html><head><title>Q3 Update</title></head><body><p>Revenue grew in every region this quarter and margins improved.</p></body></html>'::BLOB), (2, '\x89PNG\x0D\x0A\x1A\x0A\x00\x00\x00\x0DIHDR'::BLOB), (3, '<html><head><title>Point trimestriel</title></head><body><p>Le chiffre d''affaires a progresse dans toutes les regions ce trimestre.</p></body></html>'::BLOB)) SELECT x.id, x.meta['dc:title'] AS title, tika.main.detect_lang(x.content) AS language
FROM tika.main.extract_all((SELECT id, body FROM inbox WHERE tika.main.detect_mime(body) = 'text/html'), id := 'id', doc_column := 'body') AS x
ORDER BY x.id;
ocr (doc ANY)
OCR an image or scanned PDF (bytes or path) via Tika's Tesseract parser; returns NULL when Tesseract is unavailable.
OCR a scanned image read as bytes with read_blob(), using the default English model; returns the card's text starting 'LIBRARY RETURN CHECKLIST' (NULL if Tesseract is not installed).
SELECT tika.main.ocr(content)
FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/fbe9bce2524010aa5b0ec8f4456c05f4082fa1b5/notebooks/assets/scan-card.png');
Split the OCR'd text of a scanned card into its non-blank lines, one row per line (4 rows; no rows if Tesseract is not installed).
SELECT line
FROM (SELECT unnest(string_split(tika.main.ocr(content), chr(10))) AS line FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-tika/fbe9bce2524010aa5b0ec8f4456c05f4082fa1b5/notebooks/assets/scan-card.png'))
WHERE trim(line) <> '';
extract_text (doc ANY, by_page := BOOLEAN, lang := VARCHAR, ocr := BOOLEAN, strict := BOOLEAN)
Extract text, metadata, language, and page count from a document (PDF, DOCX, PPTX, XLSX, HTML, EML, RTF, ODF, images) via Apache Tika.
Extract the body text, MIME type, and page count of a single document.
SELECT content, mime, n_pages
FROM tika.main.extract_text('A short plain-text body.'::BLOB);
Split a document into one row per page (leading `page` column).
SELECT page, content
FROM tika.main.extract_text('Single page body.'::BLOB, by_page := true);
Extract from document bytes (a BLOB) and read a metadata key from the `meta` MAP.
SELECT meta['Content-Type'] AS ct
FROM tika.main.extract_text('Some bytes.'::BLOB);
2 more examples
SELECT content, mime
FROM tika.main.extract_text('Hello from a plain-text document body.'::BLOB);
SELECT meta['Content-Type'] AS content_type
FROM tika.main.extract_text('Some document bytes.'::BLOB);
metadata (doc ANY, strict := BOOLEAN)
Extract document metadata (MIME, page count, language, full metadata MAP) without the body text, via Apache Tika.
Read a document's MIME type, page count, and language without extracting the body text.
SELECT mime, n_pages, lang
FROM tika.main.metadata('A short document body.'::BLOB);
Read a single metadata field from the `meta` MAP.
SELECT meta['Content-Type'] AS ct
FROM tika.main.metadata('Some bytes.'::BLOB);
extract_all (input TABLE, doc_column := VARCHAR, id := VARCHAR, ocr := BOOLEAN, lang := VARCHAR)
Extract text + metadata for a whole column of documents (paths or bytes), with an id column passed through onto each output row.
Extract every document in an inline column of bytes, keeping the source `id` on each output row to join results back.
SELECT id, content, mime
FROM tika.main.extract_all((SELECT * FROM (VALUES (1, 'First body.'::BLOB), (2, 'Second body.'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body');
Extract from a BLOB column (`body`) of inline document bytes, with the `id` column passed through.
SELECT id, content
FROM tika.main.extract_all((SELECT * FROM (VALUES (1, 'Inline document bytes.'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body');
Language breakdown of a document corpus: extract every body with extract_all, tag it with detect_lang, and send bodies whose detect_lang_conf is below 0.5 (or undetectable) to 'und'. Returns en [1, 4] and und [5, 6] (2 docs each), then de [3] and fr [2].
SELECT CASE WHEN tika.main.detect_lang_conf(content) >= 0.5 THEN tika.main.detect_lang(content) ELSE 'und' END AS language,
count(*) AS docs, list(id ORDER BY id) AS ids
FROM tika.main.extract_all((SELECT id, body FROM (VALUES (1, 'The quarterly report shows strong growth across every region this year.'::BLOB), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les regions.'::BLOB), (3, 'Der Quartalsbericht zeigt ein starkes Wachstum in allen Regionen.'::BLOB), (4, 'Our customers renewed their contracts early and expanded their usage.'::BLOB), (5, 'OK'::BLOB), (6, 'PO-88213'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body')
GROUP BY language
ORDER BY docs DESC, language;
1 more example
Triage a mixed inbox of raw bytes: detect_mime sniffs each blob so only the HTML pages go through extract_all (the PNG, id 2, is skipped), then each page's <title> is read from the metadata map and its body language tagged with detect_lang (1 'Q3 Update' en, 3 'Point trimestriel' fr).
WITH inbox(id, body) AS (VALUES (1, '<html><head><title>Q3 Update</title></head><body><p>Revenue grew in every region this quarter and margins improved.</p></body></html>'::BLOB), (2, '\x89PNG\x0D\x0A\x1A\x0A\x00\x00\x00\x0DIHDR'::BLOB), (3, '<html><head><title>Point trimestriel</title></head><body><p>Le chiffre d''affaires a progresse dans toutes les regions ce trimestre.</p></body></html>'::BLOB)) SELECT x.id, x.meta['dc:title'] AS title, tika.main.detect_lang(x.content) AS language
FROM tika.main.extract_all((SELECT id, body FROM inbox WHERE tika.main.detect_mime(body) = 'text/html'), id := 'id', doc_column := 'body') AS x
ORDER BY x.id;
Try these queries
Extract the plain-text body and detected media type from a single document.
SELECT content, mime FROM tika.main.extract_text('A plain-text body.'::BLOB)
Uses extract_text
Read a document's media type and page count without extracting its body text.
SELECT mime, n_pages FROM tika.main.metadata('Some document bytes.'::BLOB)
Uses metadata
Detect the media (MIME) type of a document from its raw bytes.
SELECT tika.main.detect_mime('Plain text.'::BLOB)
Uses detect_mime
Detect the natural-language code of a body of text.
SELECT tika.main.detect_lang('The quick brown fox jumps over the lazy dog.')
Uses detect_lang
Batch-extract a whole column of documents, passing an id column through onto every output row.
SELECT id, content
FROM tika.main.extract_all((SELECT * FROM (VALUES (1, 'Body bytes.'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body')
Uses extract_all
Language breakdown of a document corpus: extract every body with extract_all, tag it with detect_lang, and send bodies whose detect_lang_conf is below 0.5 (or undetectable) to 'und'. Returns en [1, 4] and und [5, 6] (2 docs each), then de [3] and fr [2].
SELECT CASE WHEN tika.main.detect_lang_conf(content) >= 0.5 THEN tika.main.detect_lang(content) ELSE 'und' END AS language,
count(*) AS docs, list(id ORDER BY id) AS ids
FROM tika.main.extract_all((SELECT id, body FROM (VALUES (1, 'The quarterly report shows strong growth across every region this year.'::BLOB), (2, 'Le rapport trimestriel montre une forte croissance dans toutes les regions.'::BLOB), (3, 'Der Quartalsbericht zeigt ein starkes Wachstum in allen Regionen.'::BLOB), (4, 'Our customers renewed their contracts early and expanded their usage.'::BLOB), (5, 'OK'::BLOB), (6, 'PO-88213'::BLOB)) AS t(id, body)), id := 'id', doc_column := 'body')
GROUP BY language
ORDER BY docs DESC, language
17 more examples in the Catalog, each listed under the table or function it uses.
Apache Tika is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Docgen
Documents & media
Fill Word templates from query rows to produce invoices, letters and other DOCX or PDF documents
Documents & media
Pull tables, words with their positions, page geometry, form fields and metadata out of PDFs, and render pages to PNG
Image
Documents & media
Decode images, read EXIF and GPS tags, spot near-duplicates by perceptual hash, and make thumbnails