Vector Store API¶
Complete API reference for AsyncCockroachDBVectorStore and CockroachDBVectorStore.
langchain_cockroachdb.async_vectorstore.AsyncCockroachDBVectorStore
¶
Bases: VectorStore
Async vector store using CockroachDB native VECTOR type and C-SPANN indexes.
embeddings
property
¶
Get embeddings model.
__init__(engine, embeddings, collection_name, *, schema='public', distance_strategy=DistanceStrategy.COSINE, content_column='content', embedding_column='embedding', metadata_column='metadata', id_column='id', namespace_column='namespace', namespace=None, hybrid_search_config=None, batch_size=100, retry_max_attempts=3, retry_initial_backoff=0.1, retry_max_backoff=5.0, retry_backoff_multiplier=2.0, retry_jitter=True)
¶
Initialize async vector store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
CockroachDBEngine
|
CockroachDBEngine instance |
required |
embeddings
|
Embeddings
|
Embeddings model |
required |
collection_name
|
str
|
Table name for this collection |
required |
schema
|
str
|
Database schema (default: public) |
'public'
|
distance_strategy
|
DistanceStrategy
|
Distance metric for similarity (default: COSINE) |
COSINE
|
content_column
|
str
|
Name of content column (default: content) |
'content'
|
embedding_column
|
str
|
Name of embedding column (default: embedding) |
'embedding'
|
metadata_column
|
str
|
Name of metadata column (default: metadata) |
'metadata'
|
id_column
|
str
|
Name of ID column (default: id) |
'id'
|
namespace_column
|
str
|
Name of namespace column (default: namespace) |
'namespace'
|
namespace
|
str | None
|
Namespace for multi-tenancy isolation. When set, all operations are scoped to this namespace. Requires the table to have a namespace column (created with namespace_column param in ainit_vectorstore_table). Default: None (no namespace filtering, backward compatible). |
None
|
hybrid_search_config
|
HybridSearchConfig | None
|
Optional hybrid search configuration |
None
|
batch_size
|
int
|
Batch size for inserts - CockroachDB works best with smaller batches (default: 100) |
100
|
retry_max_attempts
|
int
|
Maximum retry attempts for operations (default: 3) |
3
|
retry_initial_backoff
|
float
|
Initial backoff delay in seconds (default: 0.1) |
0.1
|
retry_max_backoff
|
float
|
Maximum backoff delay in seconds (default: 5.0) |
5.0
|
retry_backoff_multiplier
|
float
|
Backoff multiplier (default: 2.0) |
2.0
|
retry_jitter
|
bool
|
Add randomization to backoff (default: True) |
True
|
aadd_texts(texts, metadatas=None, ids=None, **kwargs)
async
¶
Add texts to vector store with automatic retry on failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
Iterable[str]
|
Texts to add |
required |
metadatas
|
list[dict] | None
|
Optional metadata for each text |
None
|
ids
|
list[str] | None
|
Optional IDs for texts |
None
|
**kwargs
|
Any
|
Additional arguments (batch_size override supported) |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs for added texts |
aapply_vector_index(index, prefix_columns=None)
async
¶
Apply C-SPANN vector index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
CSPANNIndex
|
Index configuration |
required |
prefix_columns
|
list[str] | None
|
Optional prefix columns for multi-tenant indexes |
None
|
add_texts(texts, metadatas=None, **kwargs)
¶
Sync wrapper - not implemented for async-only store.
adelete(ids=None, **kwargs)
async
¶
Delete documents by IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str] | None
|
Document IDs to delete |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
bool | None
|
True if successful |
adrop_vector_index(index)
async
¶
Drop vector index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
CSPANNIndex
|
Index configuration |
required |
afrom_texts(texts, embedding, metadatas=None, engine=None, connection_string=None, collection_name='langchain_vectors', **kwargs)
async
classmethod
¶
Create vector store from texts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
Texts to add |
required |
embedding
|
Embeddings
|
Embeddings model |
required |
metadatas
|
list[dict] | None
|
Optional metadata |
None
|
engine
|
CockroachDBEngine | None
|
CockroachDBEngine instance |
None
|
connection_string
|
str | None
|
Connection string (if engine not provided) |
None
|
collection_name
|
str
|
Table name |
'langchain_vectors'
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncCockroachDBVectorStore
|
AsyncCockroachDBVectorStore instance |
aget_by_ids(ids)
async
¶
Get documents by their IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str]
|
List of IDs to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of Document objects found. |
amax_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, filter=None, **kwargs)
async
¶
Max marginal relevance search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
fetch_k
|
int
|
Number of candidates to fetch |
20
|
lambda_mult
|
float
|
Diversity parameter (0=max diversity, 1=max relevance) |
0.5
|
filter
|
dict | None
|
Metadata filter |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents |
asimilarity_search(query, k=4, filter=None, **kwargs)
async
¶
Search for similar documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
filter
|
dict | None
|
Metadata filter |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents |
asimilarity_search_by_vector(embedding, k=4, filter=None, **kwargs)
async
¶
Return docs most similar to embedding vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
|
list[float]
|
Embedding to look up documents similar to. |
required |
k
|
int
|
Number of results to return. |
4
|
filter
|
dict | None
|
Metadata filter. |
None
|
**kwargs
|
Any
|
Additional arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents most similar to the query vector. |
asimilarity_search_with_score(query, k=4, filter=None, query_options=None, **kwargs)
async
¶
Search for similar documents with scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
filter
|
dict | None
|
Metadata filter |
None
|
query_options
|
CSPANNQueryOptions | None
|
C-SPANN query options |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[tuple[Document, float]]
|
List of (document, score) tuples |
asimilarity_search_with_score_by_vector(embedding, k=4, filter=None, query_options=None, **kwargs)
async
¶
Search for similar documents by embedding vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
|
list[float]
|
Query embedding vector |
required |
k
|
int
|
Number of results |
4
|
filter
|
dict | None
|
Metadata filter |
None
|
query_options
|
CSPANNQueryOptions | None
|
C-SPANN query options |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[tuple[Document, float]]
|
List of (document, score) tuples |
from_texts(texts, embedding, metadatas=None, **kwargs)
classmethod
¶
Sync wrapper - not implemented for async-only store.
get_by_ids(ids)
¶
Get documents by their IDs (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
Sequence[str]
|
List of IDs to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of Document objects found. |
similarity_search(query, k=4, **kwargs)
¶
Sync wrapper - not implemented for async-only store.
langchain_cockroachdb.vectorstores.CockroachDBVectorStore
¶
Bases: AsyncCockroachDBVectorStore
Sync wrapper for AsyncCockroachDBVectorStore using background event loop.
add_texts(texts, metadatas=None, ids=None, **kwargs)
¶
Add texts to vector store (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
Iterable[str]
|
Texts to add |
required |
metadatas
|
list[dict] | None
|
Optional metadata |
None
|
ids
|
list[str] | None
|
Optional IDs |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of IDs |
apply_vector_index(index, **kwargs)
¶
Apply vector index to the table (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Any
|
Index configuration |
required |
**kwargs
|
Any
|
Additional arguments |
{}
|
delete(ids=None, **kwargs)
¶
Delete documents (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str] | None
|
Document IDs |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
bool | None
|
True if successful |
from_texts(texts, embedding, metadatas=None, engine=None, connection_string=None, collection_name='langchain_vectors', **kwargs)
classmethod
¶
Create from texts (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
Texts to add |
required |
embedding
|
Embeddings
|
Embeddings model |
required |
metadatas
|
list[dict] | None
|
Optional metadata |
None
|
engine
|
CockroachDBEngine | None
|
CockroachDBEngine instance |
None
|
connection_string
|
str | None
|
Connection string |
None
|
collection_name
|
str
|
Table name |
'langchain_vectors'
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
CockroachDBVectorStore
|
CockroachDBVectorStore instance |
max_marginal_relevance_search(query, k=4, fetch_k=20, lambda_mult=0.5, filter=None, **kwargs)
¶
MMR search (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
fetch_k
|
int
|
Candidate pool size |
20
|
lambda_mult
|
float
|
Diversity parameter |
0.5
|
filter
|
dict | None
|
Metadata filter |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents |
similarity_search(query, k=4, filter=None, **kwargs)
¶
Search for similar documents (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
filter
|
dict | None
|
Metadata filter |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents |
similarity_search_by_vector(embedding, k=4, filter=None, **kwargs)
¶
Return docs most similar to embedding vector (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding
|
list[float]
|
Embedding to look up documents similar to. |
required |
k
|
int
|
Number of results to return. |
4
|
filter
|
dict | None
|
Metadata filter. |
None
|
**kwargs
|
Any
|
Additional arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
list[Document]
|
List of documents most similar to the query vector. |
similarity_search_with_score(query, k=4, filter=None, query_options=None, **kwargs)
¶
Search with scores (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Query text |
required |
k
|
int
|
Number of results |
4
|
filter
|
dict | None
|
Metadata filter |
None
|
query_options
|
CSPANNQueryOptions | None
|
Query options |
None
|
**kwargs
|
Any
|
Additional arguments |
{}
|
Returns:
| Type | Description |
|---|---|
list[tuple[Document, float]]
|
List of (document, score) tuples |
Key Methods¶
Adding Documents¶
| Method | Async | Description |
|---|---|---|
aadd_texts() |
✓ | Add text documents |
add_texts() |
- | Sync wrapper |
aadd_documents() |
✓ | Add Document objects |
add_documents() |
- | Sync wrapper |
Searching¶
| Method | Async | Description |
|---|---|---|
asimilarity_search() |
✓ | Search by text |
similarity_search() |
- | Sync wrapper |
asimilarity_search_with_score() |
✓ | Search with scores |
asimilarity_search_by_vector() |
✓ | Search by vector |
amax_marginal_relevance_search() |
✓ | MMR search |
Index Management¶
| Method | Async | Description |
|---|---|---|
aapply_vector_index() |
✓ | Create C-SPANN index |
apply_vector_index() |
- | Sync wrapper |
adrop_vector_index() |
✓ | Drop index |
drop_vector_index() |
- | Sync wrapper |
Deleting¶
| Method | Async | Description |
|---|---|---|
adelete() |
✓ | Delete documents |
delete() |
- | Sync wrapper |
Examples¶
See Vector Store Guide for comprehensive examples.