-
Notifications
You must be signed in to change notification settings - Fork 13
PostgreSQL database integration for conversation persistence #181
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
Conversation
palaniappan-r
commented
Nov 2, 2025
- Added PostgreSQL schema with Conversation and Message tables using SQLAlchemy ORM
- Updated chat endpoints to persist conversations and added CRUD operations for conversation management
- Added a PostgreSQL service in docker-compose with automatic database initialization
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds PostgreSQL database integration for conversation persistence, enabling the chatbot to store and retrieve conversation history. The PR removes deprecated chain-based endpoints and replaces them with a unified conversation-based API.
- Adds PostgreSQL database with Docker Compose configuration and SQLAlchemy models for conversations and messages
- Implements CRUD operations for conversation and message management with new REST API endpoints
- Refactors chat endpoints to use database-backed conversation history instead of in-memory chat history
- Removes legacy chain-based routers in favor of graph-based agent retrieval
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docker-compose.yml | Adds PostgreSQL service with health checks and connects backend to database |
| docker-compose.dev.yml | Adds pgAdmin service for development database management |
| backend/src/database/models.py | Defines SQLAlchemy models for Conversation and Message entities |
| backend/src/database/crud.py | Implements database CRUD operations for conversations and messages |
| backend/src/database/config.py | Configures database connection, session management, and initialization |
| backend/src/database/init.py | Exports database module public API |
| backend/src/api/routers/conversations.py | Refactors chat endpoints to use database persistence and adds conversation management endpoints |
| backend/src/api/routers/chains.py | Removes deprecated chain-based router (file deleted) |
| backend/src/api/models/response_model.py | Adds response models for conversation and message data |
| backend/src/api/main.py | Updates router imports and adds database initialization on startup |
| backend/src/api/api_docs.md | Documents new conversation API endpoints |
| backend/pyproject.toml | Adds PostgreSQL and SQLAlchemy dependencies |
| backend/main.py | Moves app import after environment variable setup |
| backend/Dockerfile | Adds PostgreSQL client libraries and environment variables |
| backend/Dockerfile_slim | Adds PostgreSQL client libraries and environment variables |
| backend/.env.example | Adds PostgreSQL configuration variables |
Comments suppressed due to low confidence (4)
backend/src/api/routers/conversations.py:348
- The streaming endpoint does not persist user messages or assistant responses to the database. Unlike the non-streaming endpoint (get_agent_response), this function creates a conversation but never calls crud.create_message for the user input or assistant response, meaning streaming conversations won't be saved or retrievable later.
backend/src/api/routers/conversations.py:233 - The title is set to the first 100 characters of the user's question every time a conversation is created, but when an existing conversation is retrieved, its title is never updated. This creates inconsistent behavior where the first message sets the title, but subsequent messages in the same conversation cannot update it. Consider either always updating the title for new conversations or implementing a separate endpoint to update titles explicitly.
backend/src/api/routers/conversations.py:389 - The delete_conversation endpoint queries the database twice: once with get_conversation to check existence (line 386), then crud.delete_conversation queries it again internally (line 58-59 in crud.py). This is inefficient. Consider removing the existence check since crud.delete_conversation already returns a boolean indicating success, or refactor to use a single query.
backend/src/api/routers/conversations.py:360 - The POST endpoint at the root path '' creates an empty conversation without any initial message or title. This design could lead to orphaned empty conversations if clients call this endpoint but never send messages. Consider requiring an initial message or title in the request body, or implement a cleanup mechanism for empty conversations.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
- use uuid - standardise var names Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
- async bug `get_tools` - pass chat history in prompt Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Palaniappan R <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>
Signed-off-by: Jack Luar <[email protected]>