Skip to content

Python API ​

The Python library exposes VectorStore, the S3-Vectors-flavored write and read methods, and index_folder, which fills a store from a folder. Both run in-process, with no server.

The VectorStore methods ​

The Python library (SDK) exposes the S3-Vectors-flavored write and read methods. Import VectorStore and drive it in-process:

python
from duckdb_vectors import VectorStore

store = VectorStore(db_path="vectors.duckdb", backend="local:minishlab/potion-multilingual-128M")

# Chunk-first convenience: upsert raw texts.
store.add_texts(
    ids=["doc:0", "doc:1"],
    texts=["an in-process analytical database", "vectors capture similarity"],
    metadatas=[{"kind": "intro"}, {"kind": "intro"}],
)

# Hybrid search (vector + exact-token BM25, fused with RRF).
for hit in store.query("embedded database", top_k=3):
    print(hit.score, hit.chunk.chunk_id, hit.chunk.text)

# Pure vector search with a precomputed embedding.
vector = store.embedder.embed(["embedded database"])[0]
hits = store.query_vectors(vector, top_k=3)

# Read-side helpers.
store.get_vectors(["doc:0"])
store.list_vectors(limit=10)
store.count()

# Write-side helpers.
store.delete_vectors(["doc:1"])
store.close()

For metadata scoping and age decay through an injected SELECT, see the developer guide and its worked examples of injectable ranking SQL.

The VectorStore arguments ​

VectorStore accepts these arguments:

  • db_path — the DuckDB file (default vectors.duckdb).
  • backend — the embedding backend spec, e.g. local:<model> or bedrock:titan (default local:minishlab/potion-multilingual-128M).
  • embedder — pass a ready Embedder instance to bypass backend resolution.
  • settings — pass a fully-built Settings object instead of the individual arguments.

The settings table, with the environment variables and defaults, is in the configuration reference.

Index a folder and add texts ​

index_folder(store, folder, chunker=None, recursive=False) chunks every file that the chunker handles under folder and writes the chunks to store. It returns an IndexReport with the counts files, chunks, embedded, reused, written and pruned. Only the chunks whose etag is new or changed are embedded, unchanged chunks reuse their stored vector, and the chunks of files that disappeared are pruned. With no chunker, the composite chunker dispatches each file by MIME type; an explicit chunker instance wins. The user guide shows it at work.

To add content from code instead of a folder, for example skills registered as they arrive, call add_texts (or put_vectors with Chunk objects) as often as you like, then close the store:

python
store = VectorStore(db_path="vectors.duckdb")
store.add_texts(ids=["skill-a"], texts=["Rotate the access keys"], metadatas=[{"kind": "skill"}])
store.add_texts(ids=["skill-b"], texts=["Tag a release with CalVer"], metadatas=[{"kind": "skill"}])
store.close()

Keyword search needs a full-text index that DuckDB does not update row by row. Writes and deletes mark that index stale in the database file, and it is rebuilt once: when the store closes, or on the first keyword search that finds it stale, in this process or any other sharing the file. Many small writes therefore cost one rebuild, about 0.09 s for 50,000 chunks. Close the store when you are done writing, so readers find a fresh index; a writer that exits without closing loses nothing, because the next search sees the stale marker and rebuilds.

Query ​

Query with a natural-language string. Search is hybrid by default: semantic similarity plus exact-token BM25, fused with Reciprocal Rank Fusion.

python
store = VectorStore(db_path="vectors.duckdb", backend="local:minishlab/potion-multilingual-128M")
for hit in store.query("how do retries work?", top_k=5):
    print(f"{hit.score:.4f}  {hit.chunk.source}  {hit.chunk.title}")

Metadata types ​

Metadata is stored as JSON, so frontmatter values are normalized on the way in. An unquoted YAML date such as started: 2026-05-30 is stored as the ISO 8601 text 2026-05-30, and a datetime as 2026-05-30T10:00:00. Any other value that JSON cannot hold, such as a set, is stored as its str(). Mapping keys become strings. Pages that already use plain strings, numbers, booleans or lists are unchanged. ISO text sorts correctly and works in a filter:

python
hits = store.query("decommissioning", filter={"started": "2026-05-30"})

See also ​