Skip to main content

Xberg document extraction and chunking pipeline for txtai embeddings

Project description

Xberg

txtai-xberg

Feed Xberg document extraction into txtai. XbergPipeline is a plain callable that extracts text and metadata from 91+ formats — running OCR where needed — and flattens the result into documents ready for txtai.Embeddings.index. When you enable Xberg's native chunking, each chunk becomes one embedding-sized segment instead of a single blob.

Install

pip install txtai-xberg

Requires Python 3.10+. Install the txtai extra (pip install "txtai-xberg[txtai]") if txtai isn't already in your environment.

Extract

Call the pipeline with a path or a list of paths. A string returns one document; a list returns documents in input order. Batches run through Xberg's extract_batch in a single native call.

from txtai_xberg import XbergPipeline

pipeline = XbergPipeline()

doc = pipeline("report.pdf")
print(doc["content"])              # extracted markdown
print(doc["metadata"]["title"])    # source, mime_type, title, authors, languages, page_count

docs = pipeline(["report.pdf", "notes.docx"])

Index into txtai

Use to_documents to get (id, text, tags) tuples and hand them straight to Embeddings.index. Enable Xberg chunking so segments arrive sized for the model, with heading and page context in each document's tags.

from txtai import Embeddings
from txtai_xberg import XbergPipeline
from xberg import ChunkingConfig, ExtractionConfig

pipeline = XbergPipeline(
    config=ExtractionConfig(chunking=ChunkingConfig(max_characters=1000, overlap=200)),
)
documents = pipeline.to_documents(["report.pdf", "notes.docx"])

embeddings = Embeddings(path="sentence-transformers/all-MiniLM-L6-v2", content=True)
embeddings.index(documents)

for result in embeddings.search("quarterly revenue", 3):
    print(result["id"], result["text"])

Without a chunking config, to_documents emits one document per file. Chunk ids are "<source>#<chunk_index>".

Configure extraction

Pass any Xberg ExtractionConfig to control OCR, output format, chunking, and concurrency.

from xberg import ExtractionConfig, OcrConfig

pipeline = XbergPipeline(
    config=ExtractionConfig(
        output_format="markdown",
        ocr=OcrConfig(language="eng"),
        force_ocr=True,
        max_concurrent_extractions=8,
    ),
)

Async

Already inside an event loop? Use the async methods — await pipeline.acall(paths) and await pipeline.ato_documents(paths). The synchronous __call__ and to_documents wrap these with asyncio.run and must not run inside a running loop.

Errors

Per-input failures in a batch surface as an ExtractionFailedError, whose errors attribute holds Xberg's ExtractionErrorItem objects (each with an index, source, code, and message).

For the full API, see the Xberg documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

txtai_xberg-1.0.0rc41.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

txtai_xberg-1.0.0rc41-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file txtai_xberg-1.0.0rc41.tar.gz.

File metadata

  • Download URL: txtai_xberg-1.0.0rc41.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for txtai_xberg-1.0.0rc41.tar.gz
Algorithm Hash digest
SHA256 6dcc9b6d9d445ff24a178b3530181a4f97a02d9a70af60de3f0ba6107a6e8554
MD5 4fc804cbbd3209d20a0c7a8d07efe958
BLAKE2b-256 d7115ba2c5dacfc36aac6da8ac02ec8bb4ee4eb512fc6450b49f752682b9c4ae

See more details on using hashes here.

File details

Details for the file txtai_xberg-1.0.0rc41-py3-none-any.whl.

File metadata

  • Download URL: txtai_xberg-1.0.0rc41-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for txtai_xberg-1.0.0rc41-py3-none-any.whl
Algorithm Hash digest
SHA256 b1854644de84c7630b5f87323d4791d655202d8687bf015b90bdb00c2c4d1ca8
MD5 240fc553ceb111ba8193f0182997e63f
BLAKE2b-256 c4d495f6ef6e7fb7583b8a29201815cc5ead910b18b6c12d8c04ffbbd11abbe5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page