feat(sqlserver): add SQLServerChatMessageHistory#629
Open
DevNinja (0xDevNinja) wants to merge 1 commit into
Open
feat(sqlserver): add SQLServerChatMessageHistory#629DevNinja (0xDevNinja) wants to merge 1 commit into
DevNinja (0xDevNinja) wants to merge 1 commit into
Conversation
Adds `SQLServerChatMessageHistory`, an implementation of `langchain_core.chat_history.BaseChatMessageHistory` backed by a SQL Server / Azure SQL table. Messages are JSON-serialized via `message_to_dict` and stored in an `NVARCHAR(MAX)` column, keyed by `session_id`, with an auto-incrementing `id` column that preserves insertion order on read. The class supports the same connection-string conventions as `SQLServer_VectorStore`, including Entra ID authentication when the connection string carries no credentials. Closes langchain-ai#14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
SQLServerChatMessageHistory, an implementation oflangchain_core.chat_history.BaseChatMessageHistorybacked by a SQL Server / Azure SQL table. This is thechat_message_historiesintegration tracked in #14.Messages are JSON-serialized via
message_to_dictand stored in anNVARCHAR(MAX)column, keyed bysession_id, with an auto-incrementingidcolumn that preserves insertion order on read. The class supports the same connection-string conventions asSQLServer_VectorStore— including Entra ID authentication when the connection string carries no credentials — so users can reuse existing config.Closes #14
Public API
Works out of the box with
RunnableWithMessageHistory.Files
langchain_sqlserver/chat_message_histories.py— new module withSQLServerChatMessageHistory.langchain_sqlserver/__init__.py— export the new class.tests/unit_tests/test_chat_message_histories.py— 6 unit tests covering validation, Entra-ID-vs-uid/pwd routing, serialization and the empty-input fast path. Does not require a live DB.tests/unit_tests/test_imports.py— extend the__all__snapshot.tests/integration_tests/test_chat_message_histories.py— 6 integration tests (round-trip persistence, helper methods, session isolation, scopedclear, empty-batch noop, empty-session_idrejection). Uses the existingTEST_AZURESQLSERVER_TRUSTED_CONNECTION/TEST_PYODBC_CONNECTION_STRINGenv vars.Test plan
ruff check langchain_sqlserver tests— cleanmypy langchain_sqlserver tests— clean (14 source files)pytest tests/unit_tests/— 7 passed (6 new + import snapshot), 1 module skipped (pre-existing)pytest tests/integration_tests/test_chat_message_histories.pyagainst a live SQL Server / Azure SQL instance.Notes
SQLServer_VectorStoreso users get identical auth semantics across both classes. Extracting the helpers into a shared internal module is left as a follow-up so this PR stays additive.