autogen.agentchat.contrib.vectordb.base.VectorDB
VectorDB
Abstract class for vector database. A vector database is responsible for storing and retrieving documents.
Name | Description |
---|---|
*args | |
**kwargs |
Class Attributes
active_collection
embedding_function
type
Instance Methods
create_collection
Create a collection in the vector database.
Case 1. if the collection does not exist, create the collection.
Case 2. the collection exists, if overwrite is True, it will overwrite the collection.
Case 3. the collection exists and overwrite is False, if get_or_create is True, it will get the collection,
otherwise it raise a ValueError.
Name | Description | |
---|---|---|
collection_name | str | The name of the collection. Type: str |
overwrite | bool | Whether to overwrite the collection if it exists. Default is False. Type: bool Default: False |
get_or_create | bool | Whether to get the collection if it exists. Default is True. Type: bool Default: True |
Type | Description |
---|---|
Any | Any | The collection object. |
delete_collection
Delete the collection from the vector database.
Name | Description | |
---|---|---|
collection_name | str | The name of the collection. Type: str |
Type | Description |
---|---|
Any | Any |
delete_docs
Delete documents from the collection of the vector database.
Name | Description | |
---|---|---|
ids | List[ItemID] | A list of document ids. Each id is a typed ItemID .Type: list[str | int] |
collection_name | str | The name of the collection. Default is None. Type: str Default: None |
**kwargs |
Type | Description |
---|---|
None | None |
get_collection
Get the collection from the vector database.
Name | Description | |
---|---|---|
collection_name | str | The name of the collection. Default is None. If None, return the current active collection. Type: str Default: None |
Type | Description |
---|---|
Any | Any | The collection object. |
get_docs_by_ids
Retrieve documents from the collection of the vector database based on the ids.
Name | Description | |
---|---|---|
ids | List[ItemID] | A list of document ids. If None, will return all the documents. Default is None. Type: list[str | int] Default: None |
collection_name | str | The name of the collection. Default is None. Type: str Default: None |
include | List[str] | The fields to include. Default is None. If None, will include [“metadatas”, “documents”], ids will always be included. This may differ depending on the implementation. Type: list[str] | None Default: None |
**kwargs | Type: Any |
Type | Description |
---|---|
list[Document] | List[Document] | The results. |
insert_docs
Insert documents into the collection of the vector database.
Name | Description | |
---|---|---|
docs | List[Document] | A list of documents. Each document is a TypedDict Document .Type: list[Document] |
collection_name | str | The name of the collection. Default is None. Type: str Default: None |
upsert | bool | Whether to update the document if it exists. Default is False. Type: bool Default: False |
**kwargs |
Type | Description |
---|---|
None | None |
retrieve_docs
Retrieve documents from the collection of the vector database based on the queries.
Name | Description | |
---|---|---|
queries | List[str] | A list of queries. Each query is a string. Type: list[str] |
collection_name | str | The name of the collection. Default is None. Type: str Default: None |
n_results | int | The number of relevant documents to return. Default is 10. Type: int Default: 10 |
distance_threshold | float | The threshold for the distance score, only distance smaller than it will be returned. Don’t filter with it if 0. Default is -1. Type: float Default: -1 |
**kwargs | Type: Any |
Type | Description |
---|---|
list[list[tuple[Document, float]]] | QueryResults | The query results. Each query result is a list of list of tuples containing the document and the distance. |
update_docs
Update documents in the collection of the vector database.
Name | Description | |
---|---|---|
docs | List[Document] | A list of documents. Type: list[Document] |
collection_name | str | The name of the collection. Default is None. Type: str Default: None |
**kwargs |
Type | Description |
---|---|
None | None |