strands-postgres-store
A PostgreSQL + pgvector MemoryStore for Strands Agents — semantic long-term agent memory backed by native pgvector similarity search (the <=> cosine-distance operator over an HNSW index). No external vector database.
pip install strands-postgres-store
from strands import Agent
from strands.memory import MemoryManager
from strands_postgres_store import PostgresMemoryStore
store = PostgresMemoryStore(name="user-memories", url="postgresql://user:pass@localhost:5432/db")
agent = Agent(memory_manager=MemoryManager(stores=[store]))
await store.add("The user prefers dark mode", metadata={"kind": "pref"})
hits = await store.search("what theme does the user like?")
How it works
- Semantic recall via pgvector:
ORDER BY embedding <=> query(cosine distance) over an HNSW index — native ANN in Postgres. - You bring the embeddings. Default embedder is Amazon Bedrock Titan Text v2 (1024-dim, cosine); pass any
embeddercallable for OpenAI / Cohere / local models. - Each
addstores a row{id, content, embedding vector, metadata jsonb, created_at};searchembeds the query and runs the ANN search, surfacing the distance as_score. - The table, the
vectorextension, and the HNSW index are created automatically.
Requirements
The pgvector extension must be installed on the server. On Debian/Ubuntu: apt install postgresql-16-pgvector; on macOS (Homebrew): brew install pgvector; managed services (RDS, Cloud SQL, Azure) expose it as an extension. The store runs CREATE EXTENSION IF NOT EXISTS vector on init.
Configuration
PostgresMemoryStore(name, url=None, *, table_name="strands_memory", engine=None, description=None, max_search_results=None, writable=True, extraction=None, embedder=None, dimensions=1024, region_name=None)
The memory store (
strands-postgres-store) is distinct from the byte storage backend (strands-postgres-storage). Also published asstrands-store-postgres.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strands_postgres_store-0.1.0.tar.gz.
File metadata
- Download URL: strands_postgres_store-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fba36188c1a9945aa87c7b8ea555f59c101f96195d0c027294a10bb5743e8cce
|
|
| MD5 |
facd0e42c01ed4c5e6ccc62833fe1b3e
|
|
| BLAKE2b-256 |
994f0af9de73b4721d53a655a4d901aa643e7f0bc9b2735f935bc7e10aee280e
|
File details
Details for the file strands_postgres_store-0.1.0-py3-none-any.whl.
File metadata
- Download URL: strands_postgres_store-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10c5c3a60f2aab2446d6b9ef249d2645c4fa8e4122db4109c506ef32c664284f
|
|
| MD5 |
2c0069a5e3e384d60a19f82c5a8794f7
|
|
| BLAKE2b-256 |
d789a661bde77e76a24e05b89a0689b2bee5369c2e93846107d8148a8b0a2589
|