Sunday, 1 March 2026

Quadrant and Weaviate Vector Stores

 

Qdrant:

Qdrant is a vector database that excels at:
- ✅ Local development (no Docker required)
- ✅ Fast similarity search
- ✅ Flexible storage options (in-memory or persistent)
- ✅ Rich metadata filtering

It has 3 Approaches:

1. In-Memory - Fast but temporary (lost when script ends)
2. Persistent - Saved to disk (survives restarts)
3. from_documents - Easiest method (recommended)

Basic Similarity Search:
print("BASIC SIMILARITY SEARCH")

# Search for documents similar to this query
# k=2 means return the top 2 most similar documents
results = qdrant_store_memory.similarity_search(
    "Tell me about RAG",
    k=2
)

Filter on Metadata:
from qdrant_client.models import Filter, FieldCondition, MatchValue
print("SEARCH WITH METADATA FILTER")
print("-" * 80)
#metadata={"topic": ["rag", "llms", "agents"]}
# Create a filter to only search documents with topic='rag'
# Note: We use 'metadata.topic' because metadata is nested
qdrant_filter = Filter(
    must=[
        FieldCondition(
            key="metadata.topic",
            match=MatchValue(value="rag")
        )
    ]
)

# Same search, but only among filtered documents
results_filtered = qdrant_store_memory.similarity_search(
    "Tell me about RAG",
    k=2,
    filter=qdrant_filter
)

Multiple filter Conditions:
multi_filter = Filter(
    must=[
        FieldCondition(key="metadata.topic", match=MatchValue(value="rag")),
        FieldCondition(key="metadata.difficulty", match=MatchValue(value="intermediate"))
    ]
)

Create Qdrant store directly from Documents.
# Create Qdrant store directly from documents
# This is the easiest way - everything happens in one call!
qdrant_store_easy = QdrantVectorStore.from_documents(
    documents=sample_docs,          # Your documents
    embedding=embeddings,            # Embedding function
    path="./qdrant_easy",           # Local persistence (optional)
    collection_name="rag_collection" # Collection name
)

Weaviate:
This runs on Docket Image.

weaviate_client = weaviate.connect_to_local(
        host="localhost",
        port=8080,
        grpc_port=50051
    )
embeddings = OllamaEmbeddings(model="nomic-embed-text")

print("✓ Ollama embeddings initialized")
print("  Model: nomic-embed-text")
print("  Dimension: 768")

print("QDRANT FROM_DOCUMENTS (RECOMMENDED METHOD)")
# Create Qdrant store directly from documents
# This is the easiest way - everything happens in one call!
qdrant_store_easy = QdrantVectorStore.from_documents(
    documents=sample_docs,          # Your documents
    embedding=embeddings,            # Embedding function
    path="./qdrant_easy",           # Local persistence (optional)
    collection_name="rag_collection" # Collection name
)


Sample Code is under https://github.com/LeelaPrasadG/rag_langchain/blob/main/Vector_Stores_Tutorial.ipynb

No comments:

Post a Comment

Building a ReAct Agent with LangGraph & LangSmith

In this post, I walk through building a ReAct (Reasoning + Acting) agent using LangGraph and Groq's openai/gpt-oss-120b model, where the...