The EngiAI now uses a database (PostgreSQL or SQLite) to persist chat conversations. This allows you to:
- Create multiple named conversations
- Switch between conversations seamlessly
- Automatically save all messages and agent state
- Load previous conversations when you restart the app
By default, the application uses SQLite for local development, which requires no setup. Just run the app and it will automatically create a local database file at data/conversations.db. (Docker deployments default to PostgreSQL — see Docker Deployment.)
streamlit run src/ui/streamlit_app.pyThat's it! Your conversations are automatically saved locally.
For production use or when you need to share conversations across multiple users, you can use PostgreSQL.
macOS (using Homebrew):
brew install postgresql@15
brew services start postgresql@15Ubuntu/Debian:
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresqlWindows: Download and install from postgresql.org
# Connect to PostgreSQL
psql postgres
# Create database and user
CREATE DATABASE engineer_assistant;
CREATE USER engiai_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE engineer_assistant TO engiai_user;
# Exit psql
\qCreate or update your .env file:
# Copy example file
cp .env.example .env
# Edit .env and set:
DATABASE_URL=postgresql://engiai_user:your_password@localhost:5432/engineer_assistantpip install -e .This will install psycopg2-binary and sqlalchemy from pyproject.toml.
streamlit run src/ui/streamlit_app.pyThe database tables will be created automatically on first run.
The application creates four tables:
Stores conversation metadata:
id(String/UUID): Primary key, session IDname(String): Conversation namecreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestampmessage_count(Integer): Number of messagespinned(Boolean): Whether conversation is pinned to topvoice_id(String): Voice name (e.g., "George" for ElevenLabs, "alloy" for OpenAI)voice_provider(String): Voice provider ("elevenlabs" or "openai")
Stores individual messages:
id(Integer): Auto-increment primary keyconversation_id(String): Foreign key to conversationsrole(String): 'user' or 'assistant'content(Text): Message contentimages(JSON): List of image data (base64 encoded)suggested_prompts(JSON): Follow-up prompt suggestionsaudio(JSON): Audio attachment datacreated_at(DateTime): Creation timestamp
Stores LangGraph agent state:
conversation_id(String): Primary key, foreign key to conversationsagent_state(JSON): Agent messages and stateconfig(JSON): LangGraph configurationwaiting_for_confirmation(Integer): Boolean flag (0 or 1)updated_at(DateTime): Last update timestamp
Stores user settings as key-value pairs:
id(Integer): Auto-increment primary keykey(String): Setting name (unique)value(JSON): Setting valueupdated_at(DateTime): Last update timestamp
-
Create Conversation: User enters a name in the sidebar and clicks "Create New Conversation"
- Generates a unique UUID as session_id
- Creates entry in
conversationstable - Initializes empty state in
conversation_states
-
Send Message: User types a message
- Message saved to
messagestable - Agent processes and responds
- Response saved to
messagestable - Agent state saved to
conversation_states - Conversation
updated_attimestamp updated
- Message saved to
-
Switch Conversation: User selects a different conversation
- Current conversation state saved to database
- Selected conversation loaded from database
- Messages displayed in chat interface
-
Load on Startup: When app starts
- All conversations loaded from database
- Most recently updated conversation becomes active
- Messages and state restored
# SQLite (default - no setup required)
DATABASE_URL=sqlite:///data/conversations.db
# PostgreSQL (local)
DATABASE_URL=postgresql://username:password@localhost:5432/database_name
# PostgreSQL (remote - e.g., Heroku, AWS RDS)
DATABASE_URL=postgresql://username:password@host:port/database_name
# PostgreSQL (with SSL)
DATABASE_URL=postgresql://username:password@host:port/database_name?sslmode=requireIf you were using the previous version with pickle files (data/chats/*.pkl), those files are no longer used. To migrate:
-
Option 1: Start fresh (conversations will be empty)
- Just start using the new version
- Old pickle files can be deleted
-
Option 2: Manual migration (if you need old conversations)
- This requires writing a custom migration script
- Contact support or check for migration tools in the repository
# Backup
cp data/conversations.db data/conversations.backup.db
# Restore
cp data/conversations.backup.db data/conversations.db# Backup
pg_dump -U engiai_user engineer_assistant > backup.sql
# Restore
psql -U engiai_user engineer_assistant < backup.sqlpip install psycopg2-binaryCheck that PostgreSQL is running:
# macOS
brew services list
# Linux
sudo systemctl status postgresql
# Check if port is open
psql -U postgres -h localhost -p 5432Tables are created automatically. If you get this error:
- Ensure the database user has CREATE privileges
- Try manually creating tables by running the app once
- Check the database URL is correct
For SQLite:
- Consider using PostgreSQL for production
- SQLite is great for development but may be slower with many conversations
For PostgreSQL:
- Add indexes if needed (not required for typical usage)
- Consider connection pooling for high traffic
- Add Heroku Postgres addon
- Heroku automatically sets
DATABASE_URL - Deploy your app
- Create PostgreSQL database
- Copy connection string to
DATABASE_URL - Deploy app
# In Dockerfile
ENV DATABASE_URL=postgresql://user:pass@db:5432/engineer_assistant
# In docker-compose.yml
services:
db:
image: postgres:15
environment:
POSTGRES_DB: engineer_assistant
POSTGRES_USER: engiai_user
POSTGRES_PASSWORD: your_password- Never commit
.envfile - It contains sensitive credentials - Use strong passwords for PostgreSQL
- Use SSL/TLS for remote PostgreSQL connections
- Restrict database access - Only allow connections from your app server
- Regular backups - Schedule automated backups of your database
- Environment-specific configs - Use different databases for dev/staging/prod
For issues or questions:
- Check the troubleshooting section above
- Review the database schema section above
- Open an issue on GitHub with error logs