morpheus_llm.service.vdb.vector_db_service.VectorDBService#

class VectorDBService[source]#

Bases: ABC

Class used for vectorstore specific implementation.

Methods

close()

Close connection to the vector database.

count(name, **kwargs)

Returns number of rows/entities in the given resource.

create(name[, overwrite])

Create resources in the vector database.

create_from_dataframe(name, df[, overwrite])

Create resources in the vector database.

delete(name, expr, **kwargs)

Delete data in the vector database.

delete_by_keys(name, keys, **kwargs)

Delete vectors by keys from the resource.

describe(name, **kwargs)

Describe resource in the vector database.

drop(name, **kwargs)

Drop resources from the vector database.

has_store_object(name)

Check if a resource exists in the vector database.

insert(name, data, **kwargs)

Insert data into the vector database.

insert_dataframe(name, df, **kwargs)

Converts dataframe to rows and insert into the vector database resource.

list_store_objects(**kwargs)

List existing resources in the vector database.

query(name, query, **kwargs)

Query a resource in the vector database.

release_resource(name)

Release a loaded resource from the memory.

retrieve_by_keys(name, keys, **kwargs)

Retrieve the inserted vectors using keys from the resource.

similarity_search(name, **kwargs)

Perform a similarity search within the vector database.

transform(data, **kwargs)

Transform data according to the specific vector database implementation.

update(name, data, **kwargs)

Update data in the vector database.

load_resource

abstractmethod close()[source]#

Close connection to the vector database.

abstractmethod count(name, **kwargs)[source]#

Returns number of rows/entities in the given resource.

Parameters:
namestr

Name of the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
int

Returns number of rows/entities in the given resource.

abstractmethod create(name, overwrite=False, **kwargs)[source]#

Create resources in the vector database.

Parameters:
namestr

Name of the resource.

overwritebool, default False

Whether to overwrite the resource if it already exists.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

abstractmethod create_from_dataframe(
name,
df,
overwrite=False,
**kwargs,
)[source]#

Create resources in the vector database.

Parameters:
namestr

Name of the resource.

dfDataFrameType

The dataframe to create the resource from.

overwritebool, optional

Whether to overwrite the resource if it already exists. Default is False.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

abstractmethod delete(name, expr, **kwargs)[source]#

Delete data in the vector database.

Parameters:
namestr

Name of the resource.

exprtyping.Any

Delete expression.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
dict[str, typing.Any]

Returns result of the delete operation stats.

abstractmethod delete_by_keys(name, keys, **kwargs)[source]#

Delete vectors by keys from the resource.

Parameters:
namestr

Name of the resource.

keysint | str | list

Primary keys to delete vectors.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
typing.Any

Returns vectors of the given keys that are delete from the resource.

abstractmethod describe(name, **kwargs)[source]#

Describe resource in the vector database.

Parameters:
namestr

Name of the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
dict

Returns resource information.

abstractmethod drop(name, **kwargs)[source]#

Drop resources from the vector database.

Parameters:
namestr

Name of the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

abstractmethod has_store_object(name)[source]#

Check if a resource exists in the vector database.

Parameters:
namestr

Name of the resource.

Returns:
bool

Returns True if resource exists in the vector database, otherwise False.

abstractmethod insert(name, data, **kwargs)[source]#

Insert data into the vector database.

Parameters:
namestr

Name of the resource.

datalist[list] | list[dict]

Data to be inserted into the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
dict

Returns response content as a dictionary.

abstractmethod insert_dataframe(name, df, **kwargs)[source]#

Converts dataframe to rows and insert into the vector database resource.

Parameters:
namestr

Name of the resource to be inserted.

dfDataFrameType

Dataframe to be inserted.

**kwargsdict[str, typing.Any]

Additional keyword arguments containing collection configuration.

Returns:
dict

Returns response content as a dictionary.

Raises:
RuntimeError

If the resource not exists exists.

abstractmethod list_store_objects(**kwargs)[source]#

List existing resources in the vector database.

Parameters:
**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
list[str]

Returns available resouce names in the vector database.

abstractmethod query(name, query, **kwargs)[source]#

Query a resource in the vector database.

Parameters:
namestr

Name of the resource.

querystr

Query to execute on the given resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
typing.Any

Returns search results.

abstractmethod release_resource(name)[source]#

Release a loaded resource from the memory.

Parameters:
namestr

Name of the resource to release.

abstractmethod retrieve_by_keys(name, keys, **kwargs)[source]#

Retrieve the inserted vectors using keys from the resource.

Parameters:
namestr

Name of the resource.

keystyping.Any

Primary keys to get vectors.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
list[typing.Any]

Returns rows of the given keys that exists in the resource.

Perform a similarity search within the vector database.

Parameters:
namestr

Name of the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
list[list[dict]]

Returns a list of lists, where each inner list contains dictionaries representing the results of the similarity search.

transform(data, **kwargs)[source]#

Transform data according to the specific vector database implementation.

Parameters:
datatyping.Any

Data to be updated in the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
typing.Any

Returns transformed data as per the implementation.

abstractmethod update(name, data, **kwargs)[source]#

Update data in the vector database.

Parameters:
namestr

Name of the resource.

datalist[typing.Any]

Data to be updated in the resource.

**kwargsdict[str, typing.Any]

Extra keyword arguments specific to the vector database implementation.

Returns:
dict[str, typing.Any]

Returns result of the updated operation stats.