llama-index-integrations/vector_stores/llama-index-vector-stores-couchbase/README.md
This package provides Couchbase vector store integrations for LlamaIndex, offering multiple implementation options for vector similarity search based on Couchbase Server's native vector indexing capabilities.
pip install llama-index-vector-stores-couchbase
Implements Search Vector Indexes using Couchbase Search Service with vector search capabilities. Ideal for hybrid searches combining vector, full-text, and geospatial searches.
Implements both Hyperscale Vector Indexes and Composite Vector Indexes using Couchbase Query Service with SQL++ and vector search functions. Supports:
Can scale to billions of documents. Requires Couchbase Server 8.0+.
Note:
CouchbaseVectorStorehas been deprecated in version 0.4.0. Please useCouchbaseSearchVectorStoreinstead.
from llama_index.vector_stores.couchbase import CouchbaseSearchVectorStore
from couchbase.cluster import Cluster
from couchbase.auth import PasswordAuthenticator
# Connect to Couchbase
auth = PasswordAuthenticator("username", "password")
cluster = Cluster("couchbase://localhost", auth)
# Initialize vector store
vector_store = CouchbaseSearchVectorStore(
cluster=cluster,
bucket_name="my_bucket",
scope_name="my_scope",
collection_name="my_collection",
index_name="my_vector_index",
text_key="text",
embedding_key="embedding",
metadata_key="metadata",
scoped_index=True,
)
from llama_index.vector_stores.couchbase import (
CouchbaseQueryVectorStore,
QueryVectorSearchType,
QueryVectorSearchSimilarity,
)
# Initialize Query Service-based vector store
# Works with both Hyperscale Vector Indexes (pure vector search)
# and Composite Vector Indexes (vector + scalar filters)
vector_store = CouchbaseQueryVectorStore(
cluster=cluster,
bucket_name="my_bucket",
scope_name="my_scope",
collection_name="my_collection",
search_type=QueryVectorSearchType.ANN, # or QueryVectorSearchType.KNN
similarity=QueryVectorSearchSimilarity.COSINE, # Can also use string: "cosine", "euclidean", "dot_product"
nprobes=10, # Optional: number of probes for ANN search (only for ANN)
text_key="text",
embedding_key="embedding",
metadata_key="metadata",
)
The QueryVectorSearchType enum defines the type of vector search to perform:
QueryVectorSearchType.ANN - Approximate Nearest Neighbor (recommended for large datasets)QueryVectorSearchType.KNN - K-Nearest Neighbor (exact search)The QueryVectorSearchSimilarity enum provides various distance metrics:
QueryVectorSearchSimilarity.COSINE - Cosine similarity (range: -1 to 1)QueryVectorSearchSimilarity.DOT - Dot product similarityQueryVectorSearchSimilarity.L2 or EUCLIDEAN - Euclidean distanceQueryVectorSearchSimilarity.L2_SQUARED or EUCLIDEAN_SQUARED - Squared Euclidean distanceYou can also use lowercase strings: "cosine", "dot_product", "euclidean", etc.
CouchbaseQueryVectorStore)CouchbaseQueryVectorStore supports both Hyperscale Vector Indexes and Composite Vector Indexes, which use the Couchbase Query Service with SQL++ queries and vector search functions.
Purpose-built for pure vector searches at massive scale:
When to Use:
Key Characteristics:
Combines a standard Global Secondary index (GSI) with a single vector column:
When to Use:
Key Characteristics:
nprobes parameter for accuracy/speed tradeoffCouchbaseSearchVectorStore)Search Vector Indexes use Couchbase Search Service with vector search capabilities:
When to Use:
Key Characteristics:
Both implementations support metadata filtering:
MetadataFilters==, !=, >, <, >=, <=, IN, NINAND/OR conditionsThe same CouchbaseQueryVectorStore class works with both Hyperscale and Composite Vector Indexes. The choice of which underlying index type to use is determined by the index you create on your Couchbase collection.
When selecting the appropriate vector index type, consider the following factors:
Recommendations:
| Feature | Hyperscale Vector Index | Composite Vector Index | Search Vector Index |
|---|---|---|---|
| Available Since | Couchbase Server 8.0 | Couchbase Server 8.0 | Couchbase Server 7.6 |
| Dataset Size | Tens of millions to billions of documents | Tens of millions to a billion | Tens of millions (limited to ~100M documents) |
| Best For | Pure vector searches | Searches combining vector and scalar values where scalar values are less selective (≤20%); searches where scalars should exclude vectors (e.g., compliance) | Hybrid searches combining vector with keywords or geospatial data |
| Use Cases | • Content discovery | ||
| • Recommendations | |||
| • RAG workflows | |||
| • Reverse image search | |||
| • Anomaly detection | • Job search | ||
| • Content recommendations with scalar filters | |||
| • Supply chain management | |||
| • Compliance-based filtering | • E-commerce product search | ||
| • Travel recommendations | |||
| • Real estate search | |||
| Scalar Handling | Scalars and vectors evaluated simultaneously | Scalar values pre-filter data before vector search | Searches performed in parallel |
| Strengths | • High performance for pure vector searches | ||
| • Higher accuracy at lower quantizations | |||
| • Low memory footprint | |||
| • Lowest TCO for huge datasets | |||
| • Best for concurrent updates and searches | • Scalar pre-filtering reduces vector search scope | ||
| • Efficient when scalar values have low selectivity | |||
| • Can restrict searches based on scalars for compliance | |||
| • Based on familiar GSIs | • Combines semantic, Full-Text Search, and geospatial in single pass | ||
| • Uses familiar Search indexes | |||
| Limitations | Indexing can take longer relative to other index types | • Lower accuracy than Hyperscale at lower quantizations | |
| • Scalar filtering potentially misses relevant results | • Less efficient for purely numeric/scalar searches | ||
| • Limited to ~100M documents | |||
| LlamaIndex Vector Store | CouchbaseQueryVectorStore | CouchbaseQueryVectorStore | CouchbaseSearchVectorStore |
Note on Scalar Handling: A key difference between Hyperscale and Composite Vector indexes is how they handle scalar values in queries. Hyperscale Vector indexes compare vectors and scalar values at the same time. Composite Vector indexes always apply scalar filters first, and only perform vector searches on the results. This behavior means Composite Index searches can exclude relevant vectors from the search result. However, it’s useful for cases where you must exclude some vectors (even the nearest neighbors) based on scalar values. For example, it’s useful when meeting compliance requirements.
For more information, refer to: Couchbase Vector Search Documentation
MIT