Xberg-to-SurrealDB connector for document ingestion pipelines — schema management, content deduplication, chunk storage, and index configuration
Project description
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(orDimensionMismatchError), whether SurrealDB raises aServerErroror swallows the error into anINSERT IGNOREresult.
See examples/ for BM25, vector, hybrid (RRF) search, chunk traversal, and incremental
ingestion. Licensed under MIT.
Project details
Release history Release notifications | RSS feed
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 surrealdb_xberg-1.0.5.tar.gz.
File metadata
- Download URL: surrealdb_xberg-1.0.5.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0051e308a42f0818fac0036d93fed28837c1481474ae14e85c5a2f749d0771a
|
|
| MD5 |
fce8b5d2bfb8f5e03e6914e3683287cb
|
|
| BLAKE2b-256 |
02df7e221ec551a0d2b35c55314916608235d99dcdf1cc9afeab12fbad383d36
|
File details
Details for the file surrealdb_xberg-1.0.5-py3-none-any.whl.
File metadata
- Download URL: surrealdb_xberg-1.0.5-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1b0f62dc4144f72b51b1269b1008a3b1a1fa345cb2cf1e23fafc74cf138a8f1
|
|
| MD5 |
7527baa5fed5f4da4a094fac743b8250
|
|
| BLAKE2b-256 |
71439abc3304644a0811d9a961a6048ffdab117cf403b7fe0357ce06fe304918
|