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, SearchConfig,
)

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

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

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

    # --- 3. Multi-strategy index ---
    await engine.index(TableConfig(
        table="articles",
        embeddings=[
            EmbeddingConfig(key="body", source_column="body"),
            EmbeddingConfig(key="title", source_column="title"),
        ],
        bm25=[
            BM25Config(key="title_bm25", source_column="title"),
            BM25Config(key="body_bm25", source_column="body"),
        ],
        exact=[ExactConfig(key="name_exact", source_column="name")],
    ))

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

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

    # --- 6. Multiple indexes on the same table ---
    await engine.index(TableConfig(
        table="articles",
        index_id="article_titles",
        embeddings=[EmbeddingConfig(key="title_only", source_column="title")],
    ))
    results = await engine.search("gut health", "article_titles")

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.3.1.tar.gz (72.6 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.3.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dot_search-0.3.1.tar.gz
  • Upload date:
  • Size: 72.6 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.3.1.tar.gz
Algorithm Hash digest
SHA256 22b7878a5fb7fcf2cf87489a3b5bb4901fa1ad2d3fd5405101b9356822b27f82
MD5 9471c7b31fc71896447c140e23b47494
BLAKE2b-256 fb7609731ce2ca2abc560d91914250c0ae75dcd183e1d9972c6bd8a9ac878914

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dot_search-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 185edada09bb9ff2090471cd29ae9ef84ec8971045a4a17d7ccbe83d321d528f
MD5 ce0faaf564d212214d217a6b60941626
BLAKE2b-256 8b389bb71c27de82b1bce1caeec3f5a820680491c15f9a121c0ab8509301c227

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