Vector Stores#
ragbits.core.vector_stores.base.VectorStoreEntry
#
ragbits.core.vector_stores.base.VectorStoreOptions
#
Bases: Options
An object representing the options for the vector store.
model_config
class-attribute
instance-attribute
#
dict
#
dict() -> dict[str, Any]
Creates a dictionary representation of the Options instance. If a value is None, it will be replaced with a provider-specific not-given sentinel.
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
A dictionary representation of the Options instance. |
Source code in packages/ragbits-core/src/ragbits/core/options.py
ragbits.core.vector_stores.base.VectorStore
#
VectorStore(default_options: VectorStoreOptionsT | None = None, metadata_store: MetadataStore | None = None)
Bases: ConfigurableComponent[VectorStoreOptionsT]
, ABC
A class with an implementation of Vector Store, allowing to store and retrieve vectors by similarity function.
Constructs a new VectorStore instance.
PARAMETER | DESCRIPTION |
---|---|
default_options |
The default options for querying the vector store.
TYPE:
|
metadata_store |
The metadata store to use.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/base.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
ValidationError
|
The metadata_store configuration doesn't follow the expected format. |
InvalidConfigError
|
The metadata_store class can't be found or is not the correct type. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/base.py
store
abstractmethod
async
#
store(entries: list[VectorStoreEntry]) -> None
Store entries in the vector store.
PARAMETER | DESCRIPTION |
---|---|
entries |
The entries to store.
TYPE:
|
retrieve
abstractmethod
async
#
retrieve(vector: list[float], options: VectorStoreOptionsT | None = None) -> list[VectorStoreEntry]
Retrieve entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vector to search for.
TYPE:
|
options |
The options for querying the vector store.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/base.py
remove
abstractmethod
async
#
remove(ids: list[str]) -> None
Remove entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
ids |
The list of entries' IDs to remove.
TYPE:
|
list
abstractmethod
async
#
list(where: WhereQuery | None = None, limit: int | None = None, offset: int = 0) -> list[VectorStoreEntry]
List entries from the vector store. The entries can be filtered, limited and offset.
PARAMETER | DESCRIPTION |
---|---|
where |
The filter dictionary - the keys are the field names and the values are the values to filter by. Not specifying the key means no filtering.
TYPE:
|
limit |
The maximum number of entries to return.
TYPE:
|
offset |
The number of entries to skip.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/base.py
ragbits.core.vector_stores.in_memory.InMemoryVectorStore
#
InMemoryVectorStore(default_options: VectorStoreOptions | None = None, metadata_store: MetadataStore | None = None)
Bases: VectorStore[VectorStoreOptions]
A simple in-memory implementation of Vector Store, storing vectors in memory.
Constructs a new InMemoryVectorStore instance.
PARAMETER | DESCRIPTION |
---|---|
default_options |
The default options for querying the vector store.
TYPE:
|
metadata_store |
The metadata store to use.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
from_config(config: dict) -> InMemoryVectorStore
Creates and returns an instance of the InMemoryVectorStore class from the given configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing the configuration for initializing the InMemoryVectorStore instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
InMemoryVectorStore
|
An initialized instance of the InMemoryVectorStore class. |
RAISES | DESCRIPTION |
---|---|
ValidationError
|
The metadata_store configuration doesn't follow the expected format. |
InvalidConfigError
|
The metadata_store class can't be found or is not the correct type. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
store
async
#
store(entries: list[VectorStoreEntry]) -> None
Store entries in the vector store.
PARAMETER | DESCRIPTION |
---|---|
entries |
The entries to store.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
retrieve
async
#
retrieve(vector: list[float], options: VectorStoreOptions | None = None) -> list[VectorStoreEntry]
Retrieve entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vector to search for.
TYPE:
|
options |
The options for querying the vector store.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
remove
async
#
remove(ids: list[str]) -> None
Remove entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
ids |
The list of entries' IDs to remove.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
list
async
#
list(where: WhereQuery | None = None, limit: int | None = None, offset: int = 0) -> list[VectorStoreEntry]
List entries from the vector store. The entries can be filtered, limited and offset.
PARAMETER | DESCRIPTION |
---|---|
where |
The filter dictionary - the keys are the field names and the values are the values to filter by. Not specifying the key means no filtering.
TYPE:
|
limit |
The maximum number of entries to return.
TYPE:
|
offset |
The number of entries to skip.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/in_memory.py
ragbits.core.vector_stores.chroma.ChromaVectorStore
#
ChromaVectorStore(client: ClientAPI, index_name: str, distance_method: Literal['l2', 'ip', 'cosine'] = 'cosine', default_options: VectorStoreOptions | None = None, metadata_store: MetadataStore | None = None)
Bases: VectorStore[VectorStoreOptions]
Vector store implementation using Chroma.
Constructs a new ChromaVectorStore instance.
PARAMETER | DESCRIPTION |
---|---|
client |
The ChromaDB client.
TYPE:
|
index_name |
The name of the index.
TYPE:
|
distance_method |
The distance method to use.
TYPE:
|
default_options |
The default options for querying the vector store.
TYPE:
|
metadata_store |
The metadata store to use. If None, the metadata will be stored in ChromaDB.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
ValidationError
|
The client or metadata_store configuration doesn't follow the expected format. |
InvalidConfigError
|
The client or metadata_store class can't be found or is not the correct type. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py
store
async
#
store(entries: list[VectorStoreEntry]) -> None
Stores entries in the ChromaDB collection.
PARAMETER | DESCRIPTION |
---|---|
entries |
The entries to store.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py
retrieve
async
#
retrieve(vector: list[float], options: VectorStoreOptions | None = None) -> list[VectorStoreEntry]
Retrieves entries from the ChromaDB collection.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vector to query.
TYPE:
|
options |
The options for querying the vector store.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The retrieved entries. |
RAISES | DESCRIPTION |
---|---|
MetadataNotFoundError
|
If the metadata is not found. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py
remove
async
#
remove(ids: list[str]) -> None
Remove entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
ids |
The list of entries' IDs to remove.
TYPE:
|
list
async
#
list(where: WhereQuery | None = None, limit: int | None = None, offset: int = 0) -> list[VectorStoreEntry]
List entries from the vector store. The entries can be filtered, limited and offset.
PARAMETER | DESCRIPTION |
---|---|
where |
The filter dictionary - the keys are the field names and the values are the values to filter by. Not specifying the key means no filtering.
TYPE:
|
limit |
The maximum number of entries to return.
TYPE:
|
offset |
The number of entries to skip.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
RAISES | DESCRIPTION |
---|---|
MetadataNotFoundError
|
If the metadata is not found. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/chroma.py
ragbits.core.vector_stores.qdrant.QdrantVectorStore
#
QdrantVectorStore(client: AsyncQdrantClient, index_name: str, distance_method: Distance = Distance.COSINE, default_options: VectorStoreOptions | None = None, metadata_store: MetadataStore | None = None)
Bases: VectorStore[VectorStoreOptions]
Vector store implementation using Qdrant.
Constructs a new QdrantVectorStore instance.
PARAMETER | DESCRIPTION |
---|---|
client |
An instance of the Qdrant client.
TYPE:
|
index_name |
The name of the index.
TYPE:
|
distance_method |
The distance metric to use when creating the collection.
TYPE:
|
default_options |
The default options for querying the vector store.
TYPE:
|
metadata_store |
The metadata store to use. If None, the metadata will be stored in Qdrant.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
ValidationError
|
The client or metadata_store configuration doesn't follow the expected format. |
InvalidConfigError
|
The client or metadata_store class can't be found or is not the correct type. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py
store
async
#
store(entries: list[VectorStoreEntry]) -> None
Stores vector entries in the Qdrant collection.
PARAMETER | DESCRIPTION |
---|---|
entries |
List of VectorStoreEntry objects to store
TYPE:
|
RAISES | DESCRIPTION |
---|---|
QdrantException
|
If upload to collection fails. |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py
retrieve
async
#
retrieve(vector: list[float], options: VectorStoreOptions | None = None) -> list[VectorStoreEntry]
Retrieves entries from the Qdrant collection based on vector similarity.
PARAMETER | DESCRIPTION |
---|---|
vector |
The vector to query.
TYPE:
|
options |
The options for querying the vector store.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The retrieved entries. |
RAISES | DESCRIPTION |
---|---|
MetadataNotFoundError
|
If metadata cannot be retrieved |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py
remove
async
#
remove(ids: list[str]) -> None
Remove entries from the vector store.
PARAMETER | DESCRIPTION |
---|---|
ids |
The list of entries' IDs to remove.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If collection named |
Source code in packages/ragbits-core/src/ragbits/core/vector_stores/qdrant.py
list
async
#
list(where: Filter | None = None, limit: int | None = None, offset: int = 0) -> list[VectorStoreEntry]
List entries from the vector store. The entries can be filtered, limited and offset.
PARAMETER | DESCRIPTION |
---|---|
where |
Conditions for filtering results. Reference: https://qdrant.tech/documentation/concepts/filtering
TYPE:
|
limit |
The maximum number of entries to return.
TYPE:
|
offset |
The number of entries to skip.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[VectorStoreEntry]
|
The entries. |
RAISES | DESCRIPTION |
---|---|
MetadataNotFoundError
|
If the metadata is not found. |