Skip to main content

Xberg-to-SurrealDB connector for document ingestion pipelines — schema management, content deduplication, chunk storage, and index configuration

Project description

Xberg

surrealdb-xberg

Ingest documents into SurrealDB with Xberg extraction. The connector manages the schema, deduplicates by content hash, and stores the full Xberg output — content, metadata, keywords, named entities, tables, summary, detected languages, and quality score — plus optionally chunks with embeddings for vector and hybrid search.

Install

pip install surrealdb-xberg

Requires Python 3.10+ and a running SurrealDB instance:

docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root

Choose a class

Class Stores Indexes Use for
DocumentConnector Whole documents BM25 on documents Keyword search over documents
DocumentPipeline Documents + chunks BM25 + HNSW Semantic / hybrid search
DocumentPipeline(embed=False) Documents + chunks BM25 on chunks Keyword search over chunks

Both are fully async and accept any async SurrealDB connection, session, or transaction.

Quick start

import asyncio

from surrealdb import AsyncSurreal
from surrealdb_xberg import DocumentPipeline


async def main() -> None:
    async with AsyncSurreal("ws://localhost:8000") as db:
        await db.signin({"username": "root", "password": "root"})
        await db.use("app", "docs")

        pipeline = DocumentPipeline(db=db, embed=True, embedding_model="balanced")
        await pipeline.setup_schema()  # probes the embedding dimension, then creates tables + indexes

        # One extract_batch call for the whole directory, then batched idempotent inserts.
        await pipeline.ingest_directory("./papers", glob="**/*.pdf")

        # Vector search over chunks.
        embedding = await pipeline.embed_query("retrieval augmented generation")
        hits = await pipeline.client.query(
            f"SELECT document.source AS source, content, vector::distance::knn() AS distance "
            f"FROM {pipeline.chunk_table} WHERE embedding <|5,COSINE|> $embedding ORDER BY distance",
            {"embedding": embedding},
        )
        print(hits)


asyncio.run(main())

Ingestion

Every entry point extracts through Xberg, then stores idempotently (deterministic record IDs plus INSERT IGNORE, so re-ingesting the same content is a no-op):

await pipeline.ingest_file("report.pdf")
await pipeline.ingest_files(["a.pdf", "b.docx"])       # single batched extract_batch
await pipeline.ingest_directory("./corpus", glob="**/*.pdf")
await pipeline.ingest_bytes(data=raw, mime_type="application/pdf", source="upload://1")

Pass an Xberg ExtractionConfig to control extraction — OCR, keywords, NER, summarization, chunking:

from xberg import ExtractionConfig, NerConfig, SummarizationConfig

config = ExtractionConfig(ner=NerConfig(), summarization=SummarizationConfig())
connector = DocumentConnector(db=db, config=config)

DocumentPipeline injects its embedding config into whatever ChunkingConfig you provide (or a default one), preserving your max_characters/overlap/preset.

Stored fields

Each document row carries source, content, mime_type, title, authors, created_at, metadata, quality_score, content_hash, detected_languages, keywords, summary, entities (NER: category, text, start, end, confidence), and tables (markdown, page_number, cells). DocumentPipeline additionally writes a chunks table linked back to the parent document via a record link, each chunk holding its content, chunk_index, page/byte offsets, and (when enabled) its embedding.

Notes

  • SurrealDB v3 enforces HNSW dimensions server-globally. Use one embedding model per server, or separate instances; a dimension conflict raises DimensionMismatchError.
  • Ingestion failures surface as IngestionError (or DimensionMismatchError), whether SurrealDB raises a ServerError or swallows the error into an INSERT IGNORE result.

See examples/ for BM25, vector, hybrid (RRF) search, chunk traversal, and incremental ingestion. Licensed under MIT.

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

surrealdb_xberg-1.0.0rc37.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

surrealdb_xberg-1.0.0rc37-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file surrealdb_xberg-1.0.0rc37.tar.gz.

File metadata

  • Download URL: surrealdb_xberg-1.0.0rc37.tar.gz
  • Upload date:
  • Size: 18.4 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 surrealdb_xberg-1.0.0rc37.tar.gz
Algorithm Hash digest
SHA256 d8b5d30b0f95c1889aa3db9aeab5ddd53dcba5d0101564c57068a3d522de5f9c
MD5 5cd7b07871578db8d3ac3e8d20beab6d
BLAKE2b-256 13180a4cc4446de317381dd2ab1d8841e9150e86534f810bf680d65ba25b30a8

See more details on using hashes here.

File details

Details for the file surrealdb_xberg-1.0.0rc37-py3-none-any.whl.

File metadata

  • Download URL: surrealdb_xberg-1.0.0rc37-py3-none-any.whl
  • Upload date:
  • Size: 17.2 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 surrealdb_xberg-1.0.0rc37-py3-none-any.whl
Algorithm Hash digest
SHA256 7562ebacfadad9d4976efdcb78334ccad49b7740a7ed85841a542ffcb0543dec
MD5 9ec391b6f77cbfac8d9c0d265138e862
BLAKE2b-256 c43c80e522b13f3a4f1a8494d17c14cc88edb204ae5722b4ccf45ed8d921c2f5

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