Open-source, database-agnostic query agent that translates natural language into vector database operations
Project description
OpenQueryAgent
Open-source, database-agnostic query agent for vector databases.
Translate natural language into precise vector database operations across multiple backends โ with a single unified API.
โจ Features
- ๐ 8 Vector Database Adapters โ Qdrant, Milvus, pgvector, Weaviate, Pinecone, Chroma, Elasticsearch, AWS S3 Vectors
- ๐ง LLM-Powered Query Planning โ Decomposes complex queries into optimized sub-queries with automatic fallback
- ๐ Universal Filter DSL โ Write filters once, compile to any backend's native format
- ๐ก Streaming Responses โ Token-by-token answer generation with citation extraction
- ๐ Multi-DB Federation โ Query across multiple databases in a single request
- ๐๏ธ Pluggable Pipeline โ Swap any component: planner, reranker, synthesizer, LLM, embedding model
- ๐ฌ Conversation Memory โ Multi-turn dialogue with automatic token budget management
- ๐ Security Hardened โ Input validation, SQL injection prevention, credential redaction, prompt injection protection
- โ
Fully Typed โ Strict mypy with
py.typedmarker for downstream consumers
๐ Quick Start
Installation
# Core + Qdrant adapter + OpenAI LLM & embeddings
pip install openqueryagent[qdrant,openai]
# Or with Milvus
pip install openqueryagent[milvus,openai]
# Or with pgvector
pip install openqueryagent[pgvector,openai]
# Or with Elasticsearch
pip install openqueryagent[elasticsearch,openai]
# Everything
pip install openqueryagent[all]
Basic Usage
import asyncio
from openqueryagent.core.agent import QueryAgent
from openqueryagent.adapters.qdrant import QdrantAdapter
from openqueryagent.llm.openai import OpenAIProvider
from openqueryagent.embeddings.openai import OpenAIEmbedding
async def main():
# Create components
adapter = QdrantAdapter(url="localhost", port=6333)
await adapter.connect()
llm = OpenAIProvider(model="gpt-4o-mini")
embedding = OpenAIEmbedding(model="text-embedding-3-small")
# Create agent
agent = QueryAgent(
adapters={"qdrant": adapter},
llm=llm,
embedding=embedding,
)
await agent.initialize()
# Ask a question โ gets synthesized answer with citations
response = await agent.ask("What are the best products under $50?")
print(response.answer)
for citation in response.citations:
print(f" [{citation.document_id}]: {citation.text_snippet}")
# Search โ returns ranked documents without synthesis
results = await agent.search("machine learning papers", limit=5)
for doc in results.documents:
print(f" {doc.document.id}: {doc.score:.3f}")
asyncio.run(main())
Without LLM (Zero-Cost Search)
from openqueryagent.core.agent import QueryAgent
from openqueryagent.adapters.qdrant import QdrantAdapter
from openqueryagent.core.planner import SimpleQueryPlanner
agent = QueryAgent(
adapters={"qdrant": adapter},
planner=SimpleQueryPlanner(default_collection="products"),
)
# Uses SimpleQueryPlanner โ no LLM calls, just vector search
results = await agent.search("wireless headphones")
๐๏ธ Architecture
User Query
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ QueryAgent โ
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ Schema โโโโถโ Query โโโโถโ Router โ โ
โ โ Inspector โ โPlanner โ โ โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโ โโโโโโฌโโโโโโ โ
โ โ โ
โ โโโโโโผโโโโโโ โ
โ โ Executor โ (parallel) โ
โ โโโโโโฌโโโโโโ โ
โ โ โ
โ โโโโโโผโโโโโโ โ
โ โ Reranker โ (RRF) โ
โ โโโโโโฌโโโโโโ โ
โ โ โ
โ โโโโโโผโโโโโโโ โ
โ โSynthesizerโ (LLM) โ
โ โโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
AskResponse { answer, citations, query_plan }
Pipeline
| Stage | Component | Purpose |
|---|---|---|
| Plan | LLMQueryPlanner / SimpleQueryPlanner / RuleBasedPlanner |
Decompose query into sub-queries with intent detection |
| Route | QueryRouter |
Resolve collections, compile filters to native format |
| Execute | QueryExecutor |
Parallel execution with timeouts and dependency ordering |
| Rerank | RRFReranker / NoopReranker |
Reciprocal Rank Fusion for multi-source results |
| Synthesize | LLMSynthesizer |
Generate answer with [N] citation extraction |
๐ Supported Backends
Vector Databases
| Backend | Extra | Search Types | Aggregation |
|---|---|---|---|
| Qdrant | openqueryagent[qdrant] |
Vector, Keyword, Hybrid (prefetch) | Client-side scroll |
| Milvus | openqueryagent[milvus] |
Vector, Keyword, Hybrid | Client-side query |
| pgvector | openqueryagent[pgvector] |
Vector (โบ), Keyword (tsquery), Hybrid (CTE RRF) | Native SQL |
| Weaviate | openqueryagent[weaviate] |
Vector, Keyword (BM25), Hybrid | Client-side |
| Pinecone | openqueryagent[pinecone] |
Vector, Keyword, Hybrid | Client-side |
| Chroma | openqueryagent[chroma] |
Vector, Keyword | Client-side |
| Elasticsearch | openqueryagent[elasticsearch] |
Vector (kNN), Keyword (BM25), Hybrid | Native agg framework |
| AWS S3 Vectors | openqueryagent[s3vectors] |
Vector | Client-side |
LLM Providers
| Provider | Extra | Features |
|---|---|---|
| OpenAI | openqueryagent[openai] |
GPT-4o, JSON mode, streaming, Azure support |
| Anthropic | openqueryagent[anthropic] |
Claude, JSON extraction, streaming |
| Ollama | Built-in | Local models (Llama 3, Mistral, Mixtral), streaming |
| AWS Bedrock | openqueryagent[bedrock] |
Claude, Titan, Llama via Bedrock |
Embedding Providers
| Provider | Models |
|---|---|
| OpenAI | text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002 |
| Cohere | embed-english-v3.0, embed-multilingual-v3.0 |
| HuggingFace | Any sentence-transformers model |
| AWS Bedrock | Titan Embed, Cohere Embed via Bedrock |
๐ Universal Filter DSL
Write filters once, compile to any backend:
from openqueryagent.core.filters import F
# Build a filter
f = (F.price < 50) & (F.category == "electronics") & ~(F.status == "discontinued")
# The adapter's FilterCompiler translates to native format automatically
results = await agent.search("wireless headphones", filters=f)
Supported Operators
| Category | Operators |
|---|---|
| Comparison | ==, !=, <, <=, >, >= |
| Collection | in_, not_in, between |
| Text | contains, not_contains, starts_with, ends_with, regex |
| Geo | geo_radius |
| Existence | exists |
| Boolean | & (AND), ` |
๐ฌ Conversation Memory
Multi-turn dialogue with automatic context management:
response1 = await agent.ask("What products do you have in electronics?")
# Agent remembers context
response2 = await agent.ask("Which of those are under $30?")
# Uses previous context for follow-up
# Access memory directly
agent.memory.get_messages()
agent.memory.clear()
๐ ๏ธ Development
Setup
git clone https://github.com/thirukguru/openqueryagent.git
cd openqueryagent
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,qdrant,milvus,pgvector,openai,anthropic]"
Quality Checks
# Linting
ruff check openqueryagent/ tests/
# Type checking (strict)
mypy openqueryagent/
# Tests (337 passing)
pytest tests/ -v
Project Structure
openqueryagent/
โโโ core/
โ โโโ agent.py # QueryAgent โ main orchestrator
โ โโโ planner.py # LLM + Simple query planners
โ โโโ rule_planner.py # Rule-based query planner
โ โโโ router.py # Collection resolution + filter compilation
โ โโโ executor.py # Parallel execution with timeouts
โ โโโ reranker.py # NoopReranker + RRFReranker
โ โโโ synthesizer.py # LLM answer generation with citations
โ โโโ memory.py # Token-budgeted conversation history
โ โโโ schema.py # Schema inspector + caching
โ โโโ filters.py # Universal filter DSL (F proxy)
โ โโโ types.py # Pydantic v2 models + enums
โ โโโ config.py # Agent/executor configuration
โ โโโ exceptions.py # Error hierarchy
โโโ adapters/
โ โโโ base.py # VectorStoreAdapter protocol
โ โโโ qdrant.py # Qdrant adapter
โ โโโ milvus.py # Milvus adapter
โ โโโ pgvector.py # pgvector adapter
โ โโโ weaviate.py # Weaviate adapter
โ โโโ pinecone.py # Pinecone adapter
โ โโโ chroma.py # Chroma adapter
โ โโโ elasticsearch.py # Elasticsearch adapter
โ โโโ s3vectors.py # AWS S3 Vectors adapter
โ โโโ *_filters.py # Per-adapter filter compilers
โโโ llm/
โ โโโ base.py # LLMProvider protocol
โ โโโ openai.py # OpenAI provider
โ โโโ anthropic.py # Anthropic provider
โ โโโ ollama.py # Ollama provider (local)
โ โโโ bedrock.py # AWS Bedrock provider
โโโ embeddings/
โ โโโ base.py # EmbeddingProvider protocol
โ โโโ openai.py # OpenAI embeddings
โ โโโ cohere.py # Cohere embeddings
โ โโโ huggingface.py # HuggingFace embeddings
โ โโโ bedrock.py # AWS Bedrock embeddings
โโโ py.typed # PEP 561 marker
๐ Roadmap
Phase 3 โ Server Layer (Remaining)
####Sprint 9: gRPC Server
.protodefinitions for all service methods (Ask, Search, Aggregate)- Generate Python stubs with
grpcio-tools - Implement gRPC server in
server/grpc/ - Server-streaming RPC for
AskStream
TypeScript & Go SDKs
- TypeScript SDK (
sdks/typescript/)OpenQueryAgentclient class withask(),search(),aggregate()askStream()with WebSocket/SSE- Filter builder, full TypeScript types
- Published to npm
- Go SDK (
sdks/go/)- gRPC client with
Ask(),Search(),Aggregate() AskStream()with gRPC streaming- Published as Go module
- gRPC client with
Phase 5 โ Enterprise
Multi-Tenancy
- Namespace isolation per tenant
- Per-tenant configuration and rate limits
- Tenant-scoped API keys
RBAC & Audit
- Role-based collection access control
- API key scoping (read-only, admin, per-collection)
- Audit logging and usage analytics
๐ License
Apache 2.0 โ see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openqueryagent-1.0.0.tar.gz.
File metadata
- Download URL: openqueryagent-1.0.0.tar.gz
- Upload date:
- Size: 100.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7cf13f70ef8665dc6040753240105ec7b776dadb121a946b9b2391846f7e9de
|
|
| MD5 |
584f59b0911fcea4488f44cc4fffbf7a
|
|
| BLAKE2b-256 |
69f1cc0634258a9a4d36a6bcd8b51cc31cdf7d99938ab4f1a202d6af9580d4c3
|
File details
Details for the file openqueryagent-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openqueryagent-1.0.0-py3-none-any.whl
- Upload date:
- Size: 110.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b112e30af75a343b8350e3f1277cc9656c6b3731540d550910e85f60fad50e4
|
|
| MD5 |
8aa42277cd3a0efe6de9a33e21cb219d
|
|
| BLAKE2b-256 |
afdcde58ba6b8ebfadb14fcf8c59a8585fabbf1bc4612aba3949d775490f119b
|