KV Storage#
- class llama_index.storage.kvstore.FirestoreKVStore(project: Optional[str] = None, database: str = '(default)')#
Firestore Key-Value store.
- Parameters
project (str) β The project which the client acts on behalf of.
database (str) β The database name that the client targets.
- async adelete(key: str, collection: str = 'data') bool #
Delete a value from the Firestore.
- Parameters
key (str) β key
collection (str) β collection name
- async aget(key: str, collection: str = 'data') Optional[dict] #
Get a key-value pair from the Firestore.
- Parameters
key (str) β key
collection (str) β collection name
- async aget_all(collection: str = 'data') Dict[str, dict] #
Get all values from the Firestore collection.
- Parameters
collection (str) β collection name
- async aput(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the Firestore collection.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- async aput_all(kv_pairs: List[Tuple[str, dict]], collection: str = 'data', batch_size: int = 1) None #
Put a dictionary of key-value pairs into the Firestore collection.
- Parameters
kv_pairs (List[Tuple[str, dict]]) β key-value pairs
collection (str) β collection name
- delete(key: str, collection: str = 'data') bool #
Delete a value from the Firestore.
- Parameters
key (str) β key
collection (str) β collection name
- get(key: str, collection: str = 'data') Optional[dict] #
Get a key-value pair from the Firestore.
- Parameters
key (str) β key
collection (str) β collection name
- get_all(collection: str = 'data') Dict[str, dict] #
Get all values from the Firestore collection.
- Parameters
collection (str) β collection name
- put(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the Firestore collection.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- class llama_index.storage.kvstore.MongoDBKVStore(mongo_client: Any, mongo_aclient: Optional[Any] = None, uri: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None, db_name: Optional[str] = None)#
MongoDB Key-Value store.
- Parameters
mongo_client (Any) β MongoDB client
uri (Optional[str]) β MongoDB URI
host (Optional[str]) β MongoDB host
port (Optional[int]) β MongoDB port
db_name (Optional[str]) β MongoDB database name
- async adelete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- async aget(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- async aget_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- Parameters
collection (str) β collection name
- async aput(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- delete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- classmethod from_host_and_port(host: str, port: int, db_name: Optional[str] = None) MongoDBKVStore #
Load a MongoDBKVStore from a MongoDB host and port.
- Parameters
host (str) β MongoDB host
port (int) β MongoDB port
db_name (Optional[str]) β MongoDB database name
- classmethod from_uri(uri: str, db_name: Optional[str] = None) MongoDBKVStore #
Load a MongoDBKVStore from a MongoDB URI.
- Parameters
uri (str) β MongoDB URI
db_name (Optional[str]) β MongoDB database name
- get(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- get_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- Parameters
collection (str) β collection name
- put(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- class llama_index.storage.kvstore.RedisKVStore(redis_uri: Optional[str] = 'redis://127.0.0.1:6379', **kwargs: Any)#
Redis KV Store.
- Parameters
redis_client (Any) β Redis client
redis_url (Optional[str]) β Redis server URI
- Raises
ValueError β If redis-py is not installed
Examples
>>> from llama_index.storage.kvstore.redis_kvstore import RedisKVStore >>> # Create a RedisKVStore >>> redis_kv_store = RedisKVStore( >>> redis_url="redis://127.0.0.1:6379")
- async adelete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- async aget(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- async aget_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- async aput(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- delete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- classmethod from_host_and_port(host: str, port: int) RedisKVStore #
Load a RedisKVStore from a Redis host and port.
- Parameters
host (str) β Redis host
port (int) β Redis port
- classmethod from_redis_client(redis_client: Any) RedisKVStore #
Load a RedisKVStore from a Redis Client.
- Parameters
redis_client (Redis) β Redis client
- get(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- Parameters
key (str) β key
collection (str) β collection name
- get_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- put(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- Parameters
key (str) β key
val (dict) β value
collection (str) β collection name
- put_all(kv_pairs: List[Tuple[str, dict]], collection: str = 'data', batch_size: int = 1) None #
Put a dictionary of key-value pairs into the store.
- Parameters
kv_pairs (List[Tuple[str, dict]]) β key-value pairs
collection (str) β collection name
- class llama_index.storage.kvstore.SimpleKVStore(data: Optional[Dict[str, Dict[str, dict]]] = None)#
Simple in-memory Key-Value store.
- Parameters
data (Optional[DATA_TYPE]) β data to initialize the store with
- async adelete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- async aget(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- async aget_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- async aput(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- delete(key: str, collection: str = 'data') bool #
Delete a value from the store.
- classmethod from_dict(save_dict: dict) SimpleKVStore #
Load a SimpleKVStore from dict.
- classmethod from_persist_path(persist_path: str, fs: Optional[AbstractFileSystem] = None) SimpleKVStore #
Load a SimpleKVStore from a persist path and filesystem.
- get(key: str, collection: str = 'data') Optional[dict] #
Get a value from the store.
- get_all(collection: str = 'data') Dict[str, dict] #
Get all values from the store.
- persist(persist_path: str, fs: Optional[AbstractFileSystem] = None) None #
Persist the store.
- put(key: str, val: dict, collection: str = 'data') None #
Put a key-value pair into the store.
- to_dict() dict #
Save the store as dict.