Skip to main content
Install the package with Install, then import toradb.

Open a database

import toradb

db = toradb.local("./my_db")
toradb.connect(...) is an alias for the same local opener in current releases.

Create or open tables

docs = db.create_table("docs", mode="text")
existing = db.table("docs")

Ingest documents

n = docs.add([
    {"text": "Nikola Tesla alternating current motor", "tag": "history"},
    "Marie Curie studied radioactivity",
])
print(f"added {n} documents")
See Ingest for files, DataFrames, and Arrow.
results = docs.search("Nikola Tesla motor", top_k=5)
frame = results.to_pandas()
print(frame[["id", "score"]])
See Search strategies for strategy, query_vector, and explain.

SQL

out = db.sql(
    "SELECT id FROM docs SPARSE SEARCH body BM25('Nikola Tesla') LIMIT 5"
)
if hasattr(out, "to_pandas"):
    print(out.to_pandas())
else:
    print(out)  # DDL / DESCRIBE text

Reindex

msg = db.sql("CREATE INDEX idx ON docs (text) USING BM25")
# or
db.reindex("docs", using="BM25")

Export results

results.to_pandas()
results.to_polars()  # requires polars

API reference