Skip to main content

Configurable Hybrid Search Pipeline with Qdrant and FastEmbed

Project description

License: MIT Python Version PyPI version

FastEmbed Hybrid Pipeline

A configurable hybrid search pipeline for building semantic search applications with FastEmbed and Qdrant.

Features

  • 🚀 Hybrid Search: Combines dense embeddings, sparse embeddings, and late interaction embeddings for superior search performance
  • 🔧 Configurable: Customize embedding models, vector parameters, and multi-tenancy settings
  • 🔄 Batch Processing: Efficiently process and index large document collections
  • 🏢 Multi-Tenant Support: Optional partition-based multi-tenancy for SaaS applications

Installation

pip install fastembed-hybrid-pipeline

Requires Python 3.11+

Quick Start

from qdrant_client import QdrantClient
from fastembed import TextEmbedding, SparseEmbedding, LateInteractionTextEmbedding
from qdrant_client.models import Distance, VectorParams, SparseVectorParams, KeywordIndexParams
from hybrid_search import HybridPipelineConfig, HybridPipeline
import uuid

# Initialize Qdrant client
client = QdrantClient(":memory:")  # Use a local instance or Qdrant Cloud

# Configure embedding models
text_model = TextEmbedding("BAAI/bge-small-en-v1.5")
sparse_model = SparseEmbedding("Qdrant/bm25")
late_interaction_model = LateInteractionTextEmbedding("answerdotai/answerai-colbert-small-v1")

# Configure vector parameters
dense_params = VectorParams(size=text_model.dimensions, distance=Distance.COSINE)
sparse_params = SparseVectorParams()
late_interaction_params = VectorParams(size=late_interaction_model.dimensions, distance=Distance.COSINE)

# Optional: Configure multi-tenancy
partition_field = "tenant_id"
partition_index = KeywordIndexParams(minWordLength=1, maxWordLength=100)
partition_config = (partition_field, partition_index)

# Create pipeline configuration
pipeline_config = HybridPipelineConfig(
    text_embedding_config=(text_model, dense_params),
    sparse_embedding_config=(sparse_model, sparse_params),
    late_interaction_text_embedding_config=(late_interaction_model, late_interaction_params),
    partition_config=partition_config,  # Optional, for multi-tenant setup
    multi_tenant=True,                 # Set to False for single-tenant setup
    replication_factor=1,              # For production, use 2+
    shard_number=1,                    # For production, use 3+
)

# Initialize the pipeline
pipeline = HybridPipeline(
    qdrant_client=client,
    collection_name="documents",
    hybrid_pipeline_config=pipeline_config,
)

# Index documents
documents = [
    "FastEmbed is a lightweight Python library for state-of-the-art text embeddings.",
    "Qdrant is a vector database for production-ready vector search.",
    "Hybrid search combines multiple search techniques for better results."
]

payloads = [
    {"tenant_id": "acme_corp", "document_type": "library"},
    {"tenant_id": "acme_corp", "document_type": "database"},
    {"tenant_id": "acme_corp", "document_type": "technique"}
]

document_ids = [uuid.uuid4() for _ in range(len(documents))]

# Insert documents
pipeline.insert_documents(documents, payloads, document_ids)

# Search
results = pipeline.search(
    query="Which embedding library should I use?", 
    top_k=3,
    partition_filter="acme_corp",  # Only needed for multi-tenant setups
)

# Process results
for result in results:
    print(f"Score: {result.score}")
    print(f"Document: {result.payload['document']}")
    print("-" * 30)

Configuration Options

Embedding Models

The pipeline requires three types of embedding models from FastEmbed:

  1. Dense Embeddings: Traditional vector embeddings (TextEmbedding)
  2. Sparse Embeddings: Lexical-focused sparse embeddings (SparseEmbedding)
  3. Late Interaction: Special embeddings for late interaction matching (LateInteractionTextEmbedding)

Vector Parameters

Configure vector parameters for each embedding type:

  • Dense & Late Interaction: Size, distance metric (cosine, dot, euclidean)
  • Sparse: Uses default sparse vector parameters

Multi-Tenant Configuration

For SaaS applications that need to separate data by tenant:

# Enable multi-tenancy
pipeline_config = HybridPipelineConfig(
    # ... other configs ...
    partition_config=("tenant_id", KeywordIndexParams(minWordLength=1, maxWordLength=100)),
    multi_tenant=True,
)

# When searching, specify the tenant
results = pipeline.search(query="my search", partition_filter="tenant_123")

Performance Options

For production deployments:

pipeline_config = HybridPipelineConfig(
    # ... other configs ...
    replication_factor=2,  # Data redundancy for high availability
    shard_number=3,        # Data distribution for scalability
)

Development

# Clone the repository
git clone https://github.com/your-username/fastembed-hybrid-pipeline.git
cd fastembed-hybrid-pipeline

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

qdrant_hybrid_pipeline-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

qdrant_hybrid_pipeline-0.2.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qdrant_hybrid_pipeline-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for qdrant_hybrid_pipeline-0.2.0.tar.gz
Algorithm Hash digest
SHA256 87fabcc7bd079d961c88e580a8a6ecfb39f7d64d39b4b591bc6733d994afc2fc
MD5 f5c1ec0da8a102cae0bb498534a8994b
BLAKE2b-256 6c0a063bb77b311d0cc6d6b09fd5a59a1b73ae6c1901c6e891fabdb2120c6643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for qdrant_hybrid_pipeline-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d987c8204cef7f9f8a500a109c2c85796b6a414b50a6cd71dc83c3e397d259e4
MD5 afad992e1adfaad9a54d1b833b425e05
BLAKE2b-256 ee845ca8daf41d67de1199be5726497da1bf5f6dcadf64aca3e9da4e5f7099e9

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