Code
mem-postgres-memory.py
Usage
1
Set up your virtual environment
2
Set environment variables
3
Install dependencies
4
Run PgVector
5
Run Example
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Store user memories in PostgreSQL by passing PostgresDb as the agent’s database.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
# Setup Postgres
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
db = PostgresDb(db_url=db_url)
agent = Agent(
db=db,
update_memory_on_run=True,
)
agent.print_response("My name is John Doe and I like to play basketball on the weekends.")
agent.print_response("What do I do on weekends?")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Set environment variables
export OPENAI_API_KEY=xxx
$Env:OPENAI_API_KEY="xxx"
Install dependencies
uv pip install -U agno openai sqlalchemy 'psycopg[binary]'
Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18
docker run -d `
-e POSTGRES_DB=ai `
-e POSTGRES_USER=ai `
-e POSTGRES_PASSWORD=ai `
-e PGDATA=/var/lib/postgresql `
-v pgvolume:/var/lib/postgresql `
-p 5532:5432 `
--name pgvector `
agnohq/pgvector:18
Run Example
python mem-postgres-memory.py
python mem-postgres-memory.py
Was this page helpful?