PostgresChatStore(
key: object, engine: PostgresEngine, chat_store: AsyncPostgresChatStore
)
Chat Store Table stored in an Cloud SQL for PostgreSQL database.
Methods
PostgresChatStore
PostgresChatStore(
key: object, engine: PostgresEngine, chat_store: AsyncPostgresChatStore
)
PostgresChatStore constructor.
Parameters | |
---|---|
Name | Description |
key |
object
Key to prevent direct constructor usage. |
engine |
PostgresEngine
Database connection pool. |
chat_store |
AsyncPostgresChatStore
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 |
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 |
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 |
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 |
class_name
class_name() -> str
Get class name.
create
create(
engine: llama_index_cloud_sql_pg.engine.PostgresEngine,
table_name: str,
schema_name: str = "public",
) -> llama_index_cloud_sql_pg.chat_store.PostgresChatStore
Create a new PostgresChatStore instance.
Parameters | |
---|---|
Name | Description |
engine |
PostgresEngine
Postgres 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 |
PostgresChatStore |
A newly created instance of PostgresChatStore. |
create_sync
create_sync(
engine: llama_index_cloud_sql_pg.engine.PostgresEngine,
table_name: str,
schema_name: str = "public",
) -> llama_index_cloud_sql_pg.chat_store.PostgresChatStore
Create a new PostgresChatStore sync instance.
Parameters | |
---|---|
Name | Description |
engine |
PostgresEngine
Postgres 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 |
PostgresChatStore |
A newly created instance of PostgresChatStore. |
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 |
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 |