CouchbaseVectorDB

CouchbaseVectorDB(
    connection_string: str = 'couchbase://localhost',
    username: str = 'Administrator',
    password: str = 'password',
    bucket_name: str = 'vector_db',
    embedding_function: Callable = None,
    scope_name: str = '_default',
    collection_name: str = '_default',
    index_name: str = None
)

A vector database implementation that uses Couchbase as the backend.
Initialize the vector database.

Parameters:
NameDescription
connection_stringType: str

Default: ‘couchbase
usernameType: str

Default: ‘Administrator’
passwordType: str

Default: ‘password’
bucket_nameType: str

Default: ‘vector_db’
embedding_functionType: Callable

Default: None
scope_nameType: str

Default: ‘_default’
collection_nameType: str

Default: ‘_default’
index_nameType: str

Default: None

Class Attributes

active_collection



embedding_function



type



Instance Methods

create_collection

create_collection(
    self,
    collection_name: str,
    overwrite: bool = False,
    get_or_create: bool = True
) -> Collection

Create a collection in the vector database and create a vector search index in the collection.

Parameters:
NameDescription
collection_nameThe name of the collection.

Type: str
overwriteWhether to overwrite the collection if it exists.

Default is False.

Type: bool

Default: False
get_or_createWhether to get or create the collection.

Default is True

Type: bool

Default: True

create_index_if_not_exists

create_index_if_not_exists(
    self,
    index_name: str = 'vector_index',
    collection: ForwardRef('Collection') | None = None
) -> 

Creates a vector search index on the specified collection in Couchbase.

Parameters:
NameDescription
index_nameThe name of the vector search index to create.

Defaults to “vector_search_index”.

Type: str

Default: ‘vector_index’
collectionThe Couchbase collection to create the index on.

Defaults to None.

Type: ForwardRef(‘Collection’) | None

Default: None

create_vector_search_index

create_vector_search_index(
    self,
    collection,
    index_name: str | None = 'vector_index',
    similarity: Literal['l2_norm', 'dot_product'] = 'dot_product'
) -> None

Create a vector search index in the collection.

Parameters:
NameDescription
collection
index_nameType: str | None

Default: ‘vector_index’
similarityType: Literal[‘l2_norm’, ‘dot_product’]

Default: ‘dot_product’

delete_collection

delete_collection(self, collection_name: str) -> None

Delete the collection from the vector database.

Parameters:
NameDescription
collection_nameThe name of the collection.

Type: str

delete_docs

delete_docs(
    self,
    ids: list[str | int],
    collection_name: str = None,
    batch_size: int = 1000,
    **kwargs
) -> 

Delete documents from the collection of the vector database.

Parameters:
NameDescription
idsType: list[str | int]
collection_nameType: str

Default: None
batch_sizeType: int

Default: 1000
**kwargs

get_collection

get_collection(self, collection_name: str | None = None) -> Collection

Get the collection from the vector database.

Parameters:
NameDescription
collection_nameThe name of the collection.

Default is None.

If None, return the current active collection.

Type: str | None

Default: None
Returns:
TypeDescription
CollectionThe collection object (Collection)

get_docs_by_ids

get_docs_by_ids(
    self,
    ids: list[str | int] | None = None,
    collection_name: str = None,
    include: list[str] | None = None,
    **kwargs: Any
) -> list[Document]

Retrieve documents from the collection of the vector database based on the ids.

Parameters:
NameDescription
idsType: list[str | int] | None

Default: None
collection_nameType: str

Default: None
includeType: list[str] | None

Default: None
**kwargsType: Any

insert_docs

insert_docs(
    self,
    docs: list[Document],
    collection_name: str = None,
    upsert: bool = False,
    batch_size: int = 1000,
    **kwargs: Any
) -> None

Insert Documents and Vector Embeddings into the collection of the vector database. Documents are upserted in all cases.

Parameters:
NameDescription
docsType: list[Document]
collection_nameType: str

Default: None
upsertType: bool

Default: False
batch_sizeType: int

Default: 1000
**kwargsType: Any

retrieve_docs

retrieve_docs(
    self,
    queries: list[str],
    collection_name: str = None,
    n_results: int = 10,
    distance_threshold: float = -1,
    **kwargs: Any
) -> list[list[tuple[Document, float]]]

Retrieve documents from the collection of the vector database based on the queries.
Note: Distance threshold is not supported in Couchbase FTS.

Parameters:
NameDescription
queriesType: list[str]
collection_nameType: str

Default: None
n_resultsType: int

Default: 10
distance_thresholdType: float

Default: -1
**kwargsType: Any

search_index_exists

search_index_exists(self, index_name: str) -> 

Check if the specified index is ready

Parameters:
NameDescription
index_nameType: str

update_docs

update_docs(
    self,
    docs: list[Document],
    collection_name: str = None,
    batch_size: int = 1000,
    **kwargs: Any
) -> None

Update documents, including their embeddings, in the Collection.

Parameters:
NameDescription
docsType: list[Document]
collection_nameType: str

Default: None
batch_sizeType: int

Default: 1000
**kwargsType: Any

upsert_docs

upsert_docs(
    self,
    docs: list[Document],
    collection: Collection,
    batch_size: int = 1000,
    **kwargs: Any
) -> 
Parameters:
NameDescription
docsType: list[Document]
collectionType: Collection
batch_sizeType: int

Default: 1000
**kwargsType: Any