Skip to content

feat: Adding PGChatMessageHistory #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

dishaprakash
Copy link
Collaborator

feat: Adding PGChatMessageHistory along with it's documentation

Not deprecating the PostgresChatMessageHistory for now (as the deprcation for PGVector has been removed).

else:
return f"""SELECT data, type FROM "{self.schema_name}"."{self.table_name}" WHERE session_id = :session_id ORDER BY id;"""

def _convert_to_messages(self, rows: Sequence[RowMapping]) -> list[BaseMessage]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make private

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some functions to be semi private so we can override them in the google integrations. These are mostly related to how the data is to be pulled from the db or added in depending on the schema

session_id: str,
table_name: str,
store_message: bool,
schema_name: str = "public",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting:

  • Use a boolean trap (h)ttps://docs.astral.sh/ruff/rules/boolean-type-hint-positional-argument/
  • schema_name takes a default, so put it after a * operator

self,
key: object,
pool: AsyncEngine,
session_id: str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you sanitize the table name and schema name? It looks like it's possible to inject SQL

await conn.execute(text(create_table_query))
await conn.commit()

async def ainit_chat_history_table(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The engine abstraction is coupling vectorstores and chat history which are two completely different things.

Missing a compositional pattern and an admin layer for chat history + vectorstors to be able to create / drop tables

@eyurtsev
Copy link
Collaborator

eyurtsev commented Jun 9, 2025

Looks pretty good overall! A few comments:

  1. Blocking: let's sanitize input parameters to avoid sql injection attacks.
  2. Major: The engine abstraction is leaking as it is coupling two independent concepts in the same namespace.
  3. Minor: nits on linting (the ruff linter may be disabled for v2 due to some existing violations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants