Skip to main content

Augment existing database tables with vector and BM25 search

Project description

dot-search

Python Version

dot-search augments existing database tables with vector search, BM25 keyword search, and exact substring matching. Results from multiple strategies are fused via Reciprocal Rank Fusion (RRF).

Prerequisites

PostgreSQL (production)

Requires pgvector and ParadeDB pg_search:

CREATE EXTENSION vector;
CREATE EXTENSION pg_search;

SQLite (testing only)

Uses sqlite-vec. No BM25 support.

Install

pip install dot-search

Environment variables

Variable Example
DOT__EMBED_API_KEY Bearer token
DOT__EMBED_BASE_URL https://api.openai.com/v1
DOT__EMBED_MODEL text-embedding-3-small
DOT__EMBED_DIMENSION 1536

Works with any OpenAI-compatible API (OpenAI, vLLM, TGI, Ollama, etc.).

Usage

import asyncio
from dot_search import SearchEngine, TableConfig, EmbeddingConfig, BM25Config, ExactConfig

engine = SearchEngine(db_url="postgresql+asyncpg://user:pass@localhost/mydb")

async def main():
    # --- 1. Index a table with vector search ---
    await engine.index(config=TableConfig(
        table="articles",
        embeddings=[
            EmbeddingConfig(source_column="body", target_column="ds_body"),
        ],
    ))

    # --- 2. Search ---
    results = await engine.search("neural networks", "articles", limit=5)
    for r in results:
        print(r.id, r.score)

    # --- 3. Re-index (config is persisted in ds_configs) ---
    await engine.index(index_id="articles")

    # --- 4. Add more embeddings, BM25, and exact search ---
    await engine.index(config=TableConfig(
        table="articles",
        embeddings=[
            EmbeddingConfig(source_column="body", target_column="ds_body"),
            EmbeddingConfig(source_column="title", target_column="ds_title"),
        ],
        bm25=[
            BM25Config(source_column="title"),
            BM25Config(source_column="body"),
        ],
        exact=[ExactConfig(source_column="name")],
    ))

    # --- 5. Hybrid search with SQL filter and weight overrides ---
    results = await engine.search(
        "fermentation and gut health",
        "articles",
        limit=10,
        where="published_year >= 2022 AND topic = 'health'",
        embedding_weights={"ds_body": 1.0, "ds_title": 0.3},
        bm25_weights={"title": 0.5, "body": 2.0},
    )

    # --- 6. Single-strategy search ---
    results = await engine.search("fermentation", "articles", strategy="bm25")
    results = await engine.search("Dupont", "articles", strategy="exact")

    # --- 7. Multiple indexes on the same table ---
    # Use case: a lightweight title-only index for autocomplete,
    # separate from the full hybrid index above.
    await engine.index(config=TableConfig(
        table="articles",
        index_id="article_titles",
        embeddings=[EmbeddingConfig(source_column="title", target_column="ds_article_titles_title")],
    ))
    # Search against the title-only index (uses its own config, not the "articles" one)
    results = await engine.search("gut health", "article_titles", limit=5)

asyncio.run(main())

Search strategies

Strategy What it uses
"hybrid" Vector + BM25 + exact (any configured), fused via RRF (default)
"vector" Vector similarity only
"bm25" BM25 keyword search only
"exact" Substring (LIKE) search only

Contributing & Development

See docs/CONTRIBUTING.md and docs/DEVELOPMENT.md.

License

See LICENSE for details.

Contact

deepika Team — contact@deepika.ai Project: gitlab.com/deepika6190303/deepika-open-toolbox/dot-search

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

dot_search-0.2.0.tar.gz (65.5 kB view details)

Uploaded Source

Built Distribution

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

dot_search-0.2.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file dot_search-0.2.0.tar.gz.

File metadata

  • Download URL: dot_search-0.2.0.tar.gz
  • Upload date:
  • Size: 65.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dot_search-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f034c2f094eb1e95314889bda818279272f5d13a54a3e79950435933f658dd89
MD5 5205218c829591fbea82735a8ce8ed49
BLAKE2b-256 de54edadd2acd75fea13fcf1f7f793e4635715ee269801478e42e23069206699

See more details on using hashes here.

File details

Details for the file dot_search-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dot_search-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dot_search-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9ce60a7bdfc6660f169d5075cd7332a450d5aee7be8c89f2fa14abc675290f8
MD5 d72afd3aa90ab0c4145f7a5e2b34ff30
BLAKE2b-256 8647a010104dc471402f73540dd91664068e9393096abc45296d8da948241f21

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