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.