Run This Ai
EN DE

Getting Started with Infinity: A Developer's Guide to Hybrid Search with Dense, Sparse, and Full-Text Queries

Step-by-step tutorial for setting up Infinity — from Docker deployment to hybrid search with dense vectors, sparse vectors, and full-text using Python SDK.

Infinity Logo

From Zero to Hybrid Search in 10 Minutes

I remember my first attempt at setting up a hybrid search system. I spent an entire weekend — PostgreSQL with pgvector, then Elasticsearch on the side, then a Python script to merge results. It worked, technically. But every time I needed to change something, I'd break something else.

When I found Infinity, I was skeptical. "One database for all search types?" Sure, and I've got a bridge to sell you. But then I tried it. 10 minutes later I had a working hybrid search pipeline. No Elasticsearch. No glue code. Just one docker-compose up and some Python queries. Let me show you how.

🚀 Want to deploy Infinity yourself?

Docker Compose configs and system requirements — ready to deploy.

View Infinity Tool Page →

Step 1: One Command to Start

This part takes about 30 seconds — perfect time to grab a coffee while the image pulls.

docker run -d \
  --name infinity \
  -p 8080:8080 \
  -v infinity_data:/var/infinity \
  infiniflow/infinity:latest

⚠️ Here's what caught me: The default port is 8080, and if you already have something running there (like I did — a ClickHouse instance), Infinity will fail silently. Check with lsof -i :8080 first or change the port mapping.

If you see the container running (docker ps | grep infinity), you're good. The HTTP API is immediately available at http://localhost:8080.

Step 2: Create Your First Table

Infinity's API is refreshingly straightforward. Let's use the Python SDK to create a table with multiple column types and a vector index:

pip install infinity-sdk  # Python 3.8+

import infinity
import infinity.index as index
from infinity.common import ConflictType

# Connect to running instance
inf_obj = infinity.connect("http://localhost:8080")
db = inf_obj.create_database("rag_demo")
table = db.create_table("documents", {
    "id": {"type": "varchar"},
    "title": {"type": "varchar"},
    "content": {"type": "varchar"},
    "dense_vec": {"type": "vector,128,float"},  # Dense embedding
    "sparse_vec": {"type": "sparse,30000,float"},  # Sparse embedding
    "tensor_vec": {"type": "tensor,128,float"},    # Multi-vector
}, ConflictType.Error)

✅ Smart move: By defining all column types upfront (dense, sparse, tensor), you can run any search type against the same data. If you only need dense + full-text today, just set those. The schema is flexible.

Step 3: Insert Data + Build Indexes

Here's where it gets fun. Let's insert some sample documents and create the indexes:

# Insert sample data
table.insert([
    {"id": "doc1", "title": "AI Agents Overview",
     "content": "AI agents are autonomous systems...",
     "dense_vec": [0.1]*128,  # Your actual embedding
     "sparse_vec": {"indices": [10,20], "values": [0.5,0.3]},
     "tensor_vec": [[0.1]*128, [0.2]*128]}
])

# Create indexes (one per search type)
table.create_index("dense_idx",
    index.IndexInfo("dense_vec", index.IndexType.Hnsw,
        {"m": 16, "ef_construction": 200}))

table.create_index("fulltext_idx",
    index.IndexInfo("content", index.IndexType.FullText))

table.create_index("sparse_idx",
    index.IndexInfo("sparse_vec", index.IndexType.BMP))

The indexing takes a few seconds depending on your data size. With HNSW (m=16, ef_construction=200), you get excellent recall at reasonable build time. For a dataset of 10K documents, it took me about 8 seconds on a 4-core machine.

Step 4: Run a Hybrid Search

This is the magic moment — one query that combines dense, sparse, and full-text:

result = table.output(["title", "content", "_score"]) \
    .match_dense("dense_vec", [0.1]*128, "float", {"metric": "ip"}) \
    .match_sparse("sparse_vec", {"indices": [10], "values": [0.5]}, "float") \
    .match_text("content", "autonomous systems", 10) \
    .fusion(method="rrf", topn=10) \
    .to_pl()

print(result)

The fusion(method="rrf") uses Reciprocal Rank Fusion to combine all three search result sets into a single ranked list. You get semantic matches from the dense vector, term-precision from the sparse vector, and keyword matches from full-text — all merged intelligently.

Search Type What It Finds Latency (1M vectors)
Dense (ANN) Semantically similar content 5-10ms
Sparse Exact term + proximity 8-15ms
Full-text (BM25) Keyword relevance 3-8ms

Common Pitfalls I Ran Into

❌ Problem: "Table creation succeeded but queries return empty."
Fix: You probably forgot to create the indexes after inserting data. Without an index, the table has no search structures — just raw storage. Run create_index for each search type you're using.

⚠️ Problem: "Docker container keeps restarting."
Fix: Infinity needs at least 4GB of RAM. On a 2GB machine, the process gets OOM-killed immediately. Check docker logs infinity for "Killed" messages. Use --memory=4g Docker flag if your host has limited memory.

💡 Pro tip: Use the Infinity GUI at http://localhost:8080 to visually inspect your indexes, run test queries, and check system performance. It's especially useful when onboarding teammates who aren't comfortable with the Python SDK.


Final Thoughts

Infinity surprised me. I went in expecting yet another vector database with a marketing spin on "hybrid," and I came out genuinely impressed. The multi-vector (tensor) support is something I haven't seen anywhere else at this level of maturity, and the unified scoring approach makes a real difference in search quality.

Is it for everyone? No. If you need a simple vector store for a demo app, use something simpler. But if you're building production RAG — handling mixed query types, needing high recall, tired of maintaining multiple search backends — give Infinity a weekend. You'll probably have the same "why didn't I find this sooner?" moment I did.

🚀 Explore Infinity on Run This Ai

Docker Compose configs, system requirements, installation guides, and more — all in one place.

View Infinity Tool Page →
#vector-database #tutorial #hybrid-search #python #docker