Class AlloyDBChatStore (0.2.1)

AlloyDBChatStore(
    key: object, engine: AlloyDBEngine, chat_store: AsyncAlloyDBChatStore
)

Chat Store Table stored in an AlloyDB for PostgreSQL database.

Methods

AlloyDBChatStore

AlloyDBChatStore(
    key: object, engine: AlloyDBEngine, chat_store: AsyncAlloyDBChatStore
)

AlloyDBChatStore constructor.

Parameters
Name Description
key object

Key to prevent direct constructor usage.

engine AlloyDBEngine

Database connection pool.

chat_store AsyncAlloyDBChatStore

The async only ChatStore implementation

Exceptions
Type Description
Exception If constructor is directly called by the user.

add_message

add_message(
    key: str, message: llama_index.core.base.llms.types.ChatMessage
) -> None

Synchronously adds a new chat message to the specified key.

Parameters
Name Description
key str

A unique identifierfor the chat to which the message is added.

message ChatMessage

The ChatMessage object that is to be added.

adelete_last_message

adelete_last_message(
    key: str,
) -> typing.Optional[llama_index.core.base.llms.types.ChatMessage]

Asynchronously deletes the last chat message associated with a given key.

Parameter
Name Description
key str

A unique identifier for the chat whose message is to be deleted.

Returns
Type Description
Optional[ChatMessage] The ChatMessage object that was deleted, or None if no message was associated with the key or could be deleted.

adelete_message

adelete_message(
    key: str, idx: int
) -> typing.Optional[llama_index.core.base.llms.types.ChatMessage]

Asynchronously deletes a specific chat message by index from the messages associated with a given key.

Parameters
Name Description
key str

A unique identifier for the chat whose messages are to be deleted.

idx int

The index of the ChatMessage to be deleted from the list of messages.

Returns
Type Description
Optional[ChatMessage] The ChatMessage object that was deleted, or None if no message was associated with the key or could be deleted.

adelete_messages

adelete_messages(
    key: str,
) -> typing.Optional[typing.List[llama_index.core.base.llms.types.ChatMessage]]

Asynchronously deletes the chat messages associated with a specific key.

Parameter
Name Description
key str

A unique identifier for the chat whose messages are to be deleted.

Returns
Type Description
Optional[List[ChatMessage]] A list of ChatMessage objects that were deleted, or None if no messages were associated with the key or could be deleted.

aget_keys

aget_keys() -> typing.List[str]

Asynchronously retrieves a list of all keys.

Returns
Type Description
Optional[str] A list of strings representing the keys. If no keys are found, an empty list is returned.

aget_messages

aget_messages(
    key: str,
) -> typing.List[llama_index.core.base.llms.types.ChatMessage]

Asynchronously retrieves the chat messages associated with a specific key.

Parameter
Name Description
key str

A unique identifier for which the messages are to be retrieved.

Returns
Type Description
List[ChatMessage] A list of ChatMessage objects associated with the provided key. If no messages are found, an empty list is returned.

aset_messages

aset_messages(
    key: str, messages: typing.List[llama_index.core.base.llms.types.ChatMessage]
) -> None

Asynchronously sets the chat messages for a specific key.

Parameters
Name Description
key str

A unique identifier for the chat.

messages List[ChatMessage]

A list of ChatMessage objects to upsert.

async_add_message

async_add_message(
    key: str, message: llama_index.core.base.llms.types.ChatMessage
) -> None

Asynchronously adds a new chat message to the specified key.

Parameters
Name Description
key str

A unique identifierfor the chat to which the message is added.

message ChatMessage

The ChatMessage object that is to be added.

class_name

class_name() -> str

Get class name.

create

create(
    engine: llama_index_alloydb_pg.engine.AlloyDBEngine,
    table_name: str,
    schema_name: str = "public",
) -> llama_index_alloydb_pg.chat_store.AlloyDBChatStore

Create a new AlloyDBChatStore instance.

Parameters
Name Description
engine AlloyDBEngine

AlloyDB engine to use.

table_name str

Table name that stores the chat store.

schema_name str

The schema name where the table is located. Defaults to "public"

Exceptions
Type Description
ValueError If the table provided does not contain required schema.
Returns
Type Description
AlloyDBChatStore A newly created instance of AlloyDBChatStore.

create_sync

create_sync(
    engine: llama_index_alloydb_pg.engine.AlloyDBEngine,
    table_name: str,
    schema_name: str = "public",
) -> llama_index_alloydb_pg.chat_store.AlloyDBChatStore

Create a new AlloyDBChatStore sync instance.

Parameters
Name Description
engine AlloyDBEngine

AlloyDB engine to use.

table_name str

Table name that stores the chat store.

schema_name str

The schema name where the table is located. Defaults to "public"

Exceptions
Type Description
ValueError If the table provided does not contain required schema.
Returns
Type Description
AlloyDBChatStore A newly created instance of AlloyDBChatStore.

delete_last_message

delete_last_message(
    key: str,
) -> typing.Optional[llama_index.core.base.llms.types.ChatMessage]

Synchronously deletes the last chat message associated with a given key.

Parameter
Name Description
key str

A unique identifier for the chat whose message is to be deleted.

Returns
Type Description
Optional[ChatMessage] The ChatMessage object that was deleted, or None if no message was associated with the key or could be deleted.

delete_message

delete_message(
    key: str, idx: int
) -> typing.Optional[llama_index.core.base.llms.types.ChatMessage]

Synchronously deletes a specific chat message by index from the messages associated with a given key.

Parameters
Name Description
key str

A unique identifier for the chat whose messages are to be deleted.

idx int

The index of the ChatMessage to be deleted from the list of messages.

Returns
Type Description
Optional[ChatMessage] The ChatMessage object that was deleted, or None if no message was associated with the key or could be deleted.

delete_messages

delete_messages(
    key: str,
) -> typing.Optional[typing.List[llama_index.core.base.llms.types.ChatMessage]]

Synchronously deletes the chat messages associated with a specific key.

Parameter
Name Description
key str

A unique identifier for the chat whose messages are to be deleted.

Returns
Type Description
Optional[List[ChatMessage]] A list of ChatMessage objects that were deleted, or None if no messages were associated with the key or could be deleted.

get_keys

get_keys() -> typing.List[str]

Synchronously retrieves a list of all keys.

Returns
Type Description
Optional[str] A list of strings representing the keys. If no keys are found, an empty list is returned.

get_messages

get_messages(key: str) -> typing.List[llama_index.core.base.llms.types.ChatMessage]

Synchronously retrieves the chat messages associated with a specific key.

Parameter
Name Description
key str

A unique identifier for which the messages are to be retrieved.

Returns
Type Description
List[ChatMessage] A list of ChatMessage objects associated with the provided key. If no messages are found, an empty list is returned.

model_post_init

model_post_init(context: Any, /) -> None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that's what pydantic-core passes when calling it.

set_messages

set_messages(
    key: str, messages: typing.List[llama_index.core.base.llms.types.ChatMessage]
) -> None

Synchronously sets the chat messages for a specific key.

Parameters
Name Description
key str

A unique identifier for the chat.

messages List[ChatMessage]

A list of ChatMessage objects to upsert.