evofabric.core.vectorstore#

class evofabric.core.vectorstore.DBBase(BaseComponent, ABC)[source]#

Define the abstract base class for the basic vector database interface.

Parameters:
  • collection_name (str) – Database Collection Name

  • persist_directory (str) – Persistent storage directory

  • embedding (EmbedClientBase) – Embedding client for text vectorization

  • top_k (int) – Default number of results for similarity search

async persist()[source]#

Persist vector storage to disk.

Raises:

NotImplementedError

async clear_db() int[source]#

Clear the entire vector storage.

Returns:

Number of deleted documents

Return type:

int

Raises:

NotImplementedError

Execute similarity search on vector storage.

Parameters:
  • query (str) – Query text to be searched

  • k (int, optional) – Number of results returned (default: top_k)

  • filter (Optional[Dict[str, Any]], optional) – Search metadata filter

Returns:

List of database items matching the query

Return type:

List[SearchResult]

Raises:

NotImplementedError

async add_texts(items: Sequence[DBItem] | Sequence[str], metadatas: Sequence[dict] | None = None, ids: Sequence[str] | None = None) List[str][source]#

Add new database items to vector storage.

Parameters:
  • items (Union[Sequence[DBItem], Sequence[str]]) – DBItem or text list to be added

  • metadatas (Optional[Sequence[dict]], optional) – Metadata List (Optional)

  • ids (Optional[Sequence[str]], optional) – Document ID List (Optional)

Returns:

Add Project ID List

Return type:

List[str]

Raises:

NotImplementedError

async delete_by_ids(ids: List[str]) None[source]#

Delete the item according to its original ID.

Parameters:

ids (List[str]) – List of IDs to delete

Raises:

NotImplementedError

class evofabric.core.vectorstore.VectorDB(DBBase, ABC)[source]#

Abstract class for enhanced vector database operations with advanced features.

Parameters:
  • collection_name (str) – Collection Name

  • persist_directory (str, optional) – Persistent storage directory (optional). If not set, use memory mode.

  • embedding (EmbedClientBase, optional) – Embedding function (Optional)

  • top_k (int) – Default search top_k

get_vector_count() int[source]#

Get the number of vectors in the database.

Returns:

Number of Vectors

Return type:

int

Raises:

NotImplementedError

get_collection_info() Dict[str, Any][source]#

Retrieve information about the current collection.

Returns:

Collection Information Dictionary

Return type:

Dict[str, Any]

Raises:

NotImplementedError

class evofabric.core.vectorstore.ChromaDB(VectorDB)[source]#

Vector database implementation based on native ChromaDB.

Inherits from VectorDB and implements all abstract methods.

Parameters:
  • collection_name (str) – ChromaDB Collection Name

  • persist_directory (str, optional) – Persistent storage directory (optional). If not set, use memory mode.

  • embedding (EmbedClientBase) – Embedding client for text vectorization (required)

  • top_k (int) – Default number of results for similarity search

Embedded Client Requirements:

The embedding parameter must be an instance of EmbedClientBase. The framework provides two main implementations:

  1. SentenceTransformerEmbed is used for local sentence transformer model

  2. OpenAIEmbedClient Embedding based on OpenAI API

model_post_init(context: Any, /) None[source]#

Initialize ChromaDB after pydantic validation.

Parameters:

context (Any) – Pydantic Validation Context

async persist()[source]#

Persistent data. In ChromaDB, data is automatically persisted.

Returns:

None

async clear_db() int[source]#

Clear the vector storage by deleting all documents while retaining the collection.

Returns:

Number of deleted documents

Return type:

int

Perform similarity search and return a list of SearchResult objects.

Parameters:
  • query (str) – Query text

  • k (int, optional) – Number of returned results (default top_k)

  • filter (Optional[Dict[str, Any]], optional) – Metadata Filter

Returns:

Search Results List

Return type:

List[SearchResult]

async add_texts(items: Sequence[DBItem] | Sequence[str], metadatas: Sequence[dict] | None = None, ids: Sequence[str] | None = None) List[str][source]#

Add new database items to vector storage.

Parameters:
  • items (Union[Sequence[DBItem], Sequence[str]]) – DBItem or text list

  • metadatas (Optional[Sequence[dict]], optional) – Metadata List (Optional)

  • ids (Optional[Sequence[str]], optional) – Document ID List (Optional)

Returns:

Added ID List

Return type:

List[str]

async delete_by_ids(ids: List[str]) bool[source]#

Delete the vector by its ID.

Parameters:

ids (List[str]) – List of IDs to delete

Returns:

Was the deletion successful?

Return type:

bool

get_vector_count() int[source]#

Get the number of vectors stored in the collection.

Returns:

Number of Vectors

Return type:

int

get_collection_info() Dict[str, Any][source]#

Retrieve information about the current collection.

Returns:

Collection Information Dictionary

Return type:

Dict[str, Any]