Skip to main content

SQLAlchemy-inspired ORM for vector databases.

Project description

VectorAlchemy ๐Ÿงช

The ORM for Vector Databases. Define models. Search semantically. Switch backends without changing a line of code.

PyPI version Python License: MIT Tests Coverage

โš ๏ธ Alpha Notice

[!WARNING] VectorAlchemy is currently in 0.0.1a1 (Alpha).

This initial PyPI release primarily establishes the project name while core development is underway. The public API is not yet stable and may change significantly before the first stable (1.0.0) release.

We welcome early feedback, discussions, and contributors!

Project Status

VectorAlchemy is an open-source project that aims to provide a SQLAlchemy-inspired ORM for vector databases.

Current development focuses on:

  • โœ… Core architecture
  • ๐Ÿšง Query builder
  • ๐Ÿšง Qdrant adapter
  • ๐Ÿšง Embedding providers
  • ๐Ÿšง Backend abstraction

The current PyPI release (0.0.1a2) is an early alpha preview intended to reserve the package name and allow the community to follow development from the beginning.


What is VectorAlchemy?

VectorAlchemy brings SQLAlchemy-style ORM patterns to the world of vector databases. Stop writing boilerplate embedding code, wrestling with different client APIs, and juggling filter syntax for every backend. Define your model once โ€” VectorAlchemy handles the rest.

from vectoralchemy import VectorModel, TextField, VectorField

class Document(VectorModel):
    class Config:
        backend    = "qdrant"
        embedder   = "openai/text-embedding-3-small"
        embed_field = "content"

    title:   str
    content: str = TextField(embed=True)
    author:  str
    year:    int

# Insert โ€” embedding happens automatically
await Document(title="Attention Is All You Need", content="...", author="Vaswani", year=2017).save()

# Search semantically
results = await Document.search("transformer architecture", top_k=5)

# Filtered search โ€” Django-style lookups
results = await (
    Document.objects
    .filter(year__gte=2020, author__in=["Vaswani", "LeCun"])
    .search("self-attention mechanism")
    .top_k(10)
    .min_score(0.75)
    .all()
)

# RAG context โ€” ready to inject into your LLM prompt
context = await Document.objects.search("transformers").top_k(5).as_context()

Features

Feature Description
๐Ÿ— Model Definition Pydantic-inspired class-based models with typed fields
๐Ÿ” Semantic Search Auto-embed queries, search by text or raw vector
๐Ÿ”— Chainable Queries Django-style QuerySet with filter, exclude, top_k, min_score
๐ŸŽ› Filter AST Backend-agnostic filter compilation for all 6 backends
๐Ÿ”€ Hybrid Search Dense + sparse with Reciprocal Rank Fusion (RRF)
๐Ÿ”Œ 6 Backends Qdrant, Pinecone, Weaviate, Milvus, Chroma, pgvector
๐Ÿค– 4 Embedders OpenAI, Cohere, HuggingFace, Ollama
๐Ÿ”„ Backend Swap Change one line in Config โ€” zero other changes
๐Ÿ“ฆ Bulk Ops Auto-batched insert_many with configurable chunk size
๐Ÿงช RAG-ready .as_context() formats results for LLM prompt injection
โšก Async-native Built on asyncio throughout
๐Ÿ›  CLI Migrations, inspect, bench tools (coming in Phase 4)

Supported Backends

Backend Status Install
Qdrant ๐Ÿšง Phase 2 pip install vectoralchemy[qdrant]
Chroma ๐Ÿšง Phase 3 pip install vectoralchemy[chroma]
pgvector ๐Ÿšง Phase 3 pip install vectoralchemy[pgvector]
Pinecone ๐Ÿšง Phase 3 pip install vectoralchemy[pinecone]
Weaviate ๐Ÿšง Phase 3 pip install vectoralchemy[weaviate]
Milvus ๐Ÿšง Phase 3 pip install vectoralchemy[milvus]

Alpha Notice

The current release is intended for experimentation and early adopters. APIs may change without backward compatibility until the first stable release.

Installation

# Core only
pip install vectoralchemy

# With a specific backend
pip install vectoralchemy[qdrant]
pip install vectoralchemy[pinecone]
pip install vectoralchemy[chroma]
pip install vectoralchemy[pgvector]
pip install vectoralchemy[weaviate]
pip install vectoralchemy[milvus]

# With embedding provider
pip install vectoralchemy[qdrant,openai]
pip install vectoralchemy[qdrant,huggingface]

# Everything
pip install vectoralchemy[all]

Quick Start

1. Configure

from vectoralchemy import configure

configure(
    default_backend   = "qdrant",
    backend_url       = "http://localhost:6333",
    default_embedder  = "openai/text-embedding-3-small",
    embedding_api_key = "sk-...",
)

Or via environment variables:

VECTORALCHEMY_BACKEND=qdrant
VECTORALCHEMY_BACKEND_URL=http://localhost:6333
VECTORALCHEMY_EMBEDDER=openai/text-embedding-3-small
OPENAI_API_KEY=sk-...

2. Define a Model

from vectoralchemy import VectorModel, VectorField, TextField

class BlogPost(VectorModel):
    class Config:
        backend     = "qdrant"
        collection  = "blog_posts"
        embedder    = "openai/text-embedding-3-small"
        embed_field = "body"

    title:    str
    body:     str  = TextField(embed=True)
    author:   str
    category: str
    views:    int
    embedding: list[float] = VectorField(dims=1536)

3. Insert Data

post = BlogPost(
    title="Understanding Transformers",
    body="The transformer architecture revolutionized NLP...",
    author="Alice",
    category="AI",
    views=1500,
)
await post.save()

# Bulk insert
await BlogPost.insert_many([post1, post2, post3, ...])

4. Search & Filter

# Simple semantic search
results = await BlogPost.search("attention mechanism", top_k=5)

# With filters
results = await (
    BlogPost.objects
    .filter(category="AI")
    .filter(views__gte=1000)
    .search("neural networks")
    .top_k(10)
    .all()
)

# Exclude
results = await BlogPost.objects.exclude(author="Anonymous").search("LLMs").all()

# Hybrid search (dense + sparse)
results = await (
    BlogPost.objects
    .hybrid_search("BERT pretraining", alpha=0.7)
    .top_k(10)
    .all()
)

5. RAG Integration

question = "How do transformers handle long sequences?"

# Retrieve relevant context
context = await (
    BlogPost.objects
    .filter(category="AI")
    .search(question)
    .top_k(5)
    .as_context()
)

# Inject into your LLM prompt
prompt = f"""Answer the question based on the context below.

Context:
{context}

Question: {question}
Answer:"""

Filter Operators

VectorAlchemy uses Django-style double-underscore lookup syntax:

.filter(year=2020)              # exact match (implicit __eq)
.filter(year__eq=2020)          # explicit equal
.filter(year__ne=2020)          # not equal
.filter(year__gt=2020)          # greater than
.filter(year__gte=2020)         # greater than or equal
.filter(year__lt=2023)          # less than
.filter(year__lte=2023)         # less than or equal
.filter(author__in=["A", "B"])  # value in list
.filter(author__nin=["X"])      # value not in list
.filter(tags__contains="nlp")   # list/string contains
.filter(title__startswith="Att")# string starts with
.filter(title__endswith=".pdf") # string ends with
.filter(abstract__exists=True)  # field exists / not null
.filter(year__range=[2018,2023]) # between (inclusive)

Multiple filters are AND-ed by default:

.filter(year__gte=2020).filter(author="Vaswani")
# โ†’ year >= 2020 AND author == "Vaswani"

Switching Backends

The only change needed is in your model's Config:

class Document(VectorModel):
    class Config:
        backend = "chroma"    # โ† change this line only
        # ...rest stays the same
Environment Backend
Local development chroma (no auth, in-memory option)
Staging qdrant (self-hosted Docker)
Production pinecone or weaviate (managed cloud)
Existing PostgreSQL stack pgvector

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    VectorAlchemy ORM                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚   Model Layer    โ”‚   Query Layer    โ”‚  Embedding Layer  โ”‚
โ”‚  VectorModel     โ”‚  QuerySet        โ”‚  OpenAI           โ”‚
โ”‚  VectorField     โ”‚  FilterParser    โ”‚  Cohere           โ”‚
โ”‚  TextField       โ”‚  Filter AST      โ”‚  HuggingFace      โ”‚
โ”‚  ModelRegistry   โ”‚  QueryExecutor   โ”‚  Ollama           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                   Adapter Layer                          โ”‚
โ”‚  BaseAdapter โ†’ compile_filter() โ†’ backend native format  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Qdrant โ”‚ Pinecone โ”‚Weaviateโ”‚ Milvus โ”‚ Chroma โ”‚ pgvector โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Roadmap

  • Phase 1 โ€” Core architecture (model, fields, filter AST, adapter interface)
  • Phase 2 โ€” Qdrant adapter + OpenAI embeddings (full end-to-end MVP)
  • Phase 3 โ€” Chroma, pgvector, Pinecone, Weaviate, Milvus adapters
  • Phase 4 โ€” Hybrid search, migrations CLI, batch ops, embedding cache
  • Phase 5 โ€” Docs site, PyPI release, community launch

Coming Soon

  • SQLAlchemy-style declarative models
  • Async QuerySet API
  • Automatic embedding generation
  • Hybrid dense + sparse retrieval
  • Backend-agnostic filter compiler
  • Multi-backend support
  • CLI tools
  • Migrations
  • Comprehensive documentation

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

git clone https://github.com/tasmimul-huda/VectorAlchemy.git
cd vectoralchemy
pip install -e ".[dev]"
pytest

License

MIT โ€” see LICENSE.


Built for the LLM era. Inspired by SQLAlchemy. Powered by community.

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

vectoralchemy-0.0.1a2.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

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

vectoralchemy-0.0.1a2-py3-none-any.whl (83.9 kB view details)

Uploaded Python 3

File details

Details for the file vectoralchemy-0.0.1a2.tar.gz.

File metadata

  • Download URL: vectoralchemy-0.0.1a2.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vectoralchemy-0.0.1a2.tar.gz
Algorithm Hash digest
SHA256 babc86654f3af1b47c41db7f01ba4c286686a6665bd7dd311bbd1b7b48ed9417
MD5 a27a5b3efa249dedb35bd554e129ef1e
BLAKE2b-256 562f91cefad3a80077ff319b8dc36619e01e734b33319a81712caee9768f9e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for vectoralchemy-0.0.1a2.tar.gz:

Publisher: publish.yml on tasmimul-huda/VectorAlchemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vectoralchemy-0.0.1a2-py3-none-any.whl.

File metadata

  • Download URL: vectoralchemy-0.0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 83.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vectoralchemy-0.0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 80d4c871e183e0d77d951cb840b4c50a8e9300bdd94a9488c3cd85f96dca126a
MD5 b0640bcbff60c97d23b3f212bc23d88e
BLAKE2b-256 239bbb9f2668c4b37389d65229e8ad64b17ebd5b86e43f81c703bda8529e8836

See more details on using hashes here.

Provenance

The following attestation bundles were made for vectoralchemy-0.0.1a2-py3-none-any.whl:

Publisher: publish.yml on tasmimul-huda/VectorAlchemy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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