pgvectorscale is the semantic memory backbone of the mindX autonomous intelligence platform, providing vector similarity search capabilities for context-aware reasoning and self-improvement.
Status: ✅ DEPLOYED & OPERATIONAL Integration: PostgreSQL 15+ with pgvector extension Architecture: Dual-write mode (PostgreSQL + JSON files) Performance: <100ms semantic search queries with 1M+ vectors
memories - Main Memory StorageCREATE TABLE memories (
memory_id VARCHAR(64) PRIMARY KEY,
agent_id VARCHAR(255) NOT NULL,
memory_type VARCHAR(50) NOT NULL,
importance INTEGER NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
content JSONB NOT NULL,
context JSONB,
tags TEXT[],
parent_memory_id VARCHAR(64),
created_at TIMESTAMPTZ DEFAULT NOW()
);
memory_embeddings - Vector StorageCREATE TABLE memory_embeddings (
memory_id VARCHAR(64) PRIMARY KEY REFERENCES memories(memory_id) ON DELETE CASCADE,
embedding vector(384),
text_content TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
resource_metrics - Performance MonitoringCREATE TABLE resource_metrics (
metric_id SERIAL PRIMARY KEY,
agent_id VARCHAR(255),
timestamp TIMESTAMPTZ NOT NULL,
cpu_percent FLOAT,
memory_percent FLOAT,
disk_percent FLOAT,
network_bytes_sent BIGINT,
network_bytes_recv BIGINT,
process_count INTEGER,
metrics JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
memory_relationships - Context ThreadingCREATE TABLE memory_relationships (
relationship_id SERIAL PRIMARY KEY,
parent_memory_id VARCHAR(64) REFERENCES memories(memory_id),
child_memory_id VARCHAR(64) REFERENCES memories(memory_id),
relationship_type VARCHAR(50),
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- IVFFlat index for cosine similarity search
CREATE INDEX idx_embeddings_vector ON memory_embeddings USING ivfflat (embedding vector_cosine_ops);
-- Metadata indexes for filtering
CREATE INDEX idx_memories_agent_timestamp ON memories(agent_id, timestamp DESC);
CREATE INDEX idx_memories_type ON memories(memory_type);
CREATE INDEX idx_memories_tags ON memories USING GIN(tags);
CREATE INDEX idx_resource_metrics_agent_time ON resource_metrics(agent_id, timestamp DESC);
# Run the auto-installer
sudo ./scripts/install_pgvectorscale.sh
Setup Python configuration
python scripts/setup_memory_db.py
Install Python dependencies
pip install psycopg2-binary pgvector sentence-transformers asyncpg
# Ubuntu 22.04+
sudo apt-get install postgresql-14 postgresql-contrib-14
Linux Mint (Ubuntu-based)
sudo apt-get install postgresql postgresql-contrib
# Download and compile pgvector
cd /tmp
git clone --branch v0.7.0 https://github.com/pgvector/pgvector.git
cd pgvector
make
sudo make install
Enable extension in database
sudo -u postgres psql -d mindx_memory -c "CREATE EXTENSION IF NOT EXISTS vector;"
# Create database and user
sudo -u postgres psql -c "CREATE USER mindx WITH PASSWORD 'mindx_password_2024_secure';"
sudo -u postgres psql -c "CREATE DATABASE mindx_memory OWNER mindx;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE mindx_memory TO mindx;"
# Database connection
export MINDX_DB_PASSWORD="mindx_password_2024_secure"
Optional: Custom database settings
export MINDX_DB_HOST="localhost"
export MINDX_DB_PORT="5432"
export MINDX_DB_NAME="mindx_memory"
export MINDX_DB_USER="mindx"
{
"memory": {
"storage_backend": "postgresql",
"postgresql": {
"host": "localhost",
"port": 5432,
"database": "mindx_memory",
"user": "mindx",
"password_env": "MINDX_DB_PASSWORD",
"pool_size": 10,
"max_overflow": 20
},
"embeddings": {
"model": "all-MiniLM-L6-v2",
"dimensions": 384,
"device": "cpu"
},
"vector_search": {
"default_limit": 10,
"min_similarity": 0.5,
"index_type": "ivfflat"
},
"resource_integration": {
"auto_store_metrics": true,
"store_interval_seconds": 60,
"correlation_window_days": 7
}
}
}
POST /api/rage/memory/retrieve
Content-Type: application/json
{
"query": "agent performance optimization",
"agent_id": "mindxagent",
"top_k": 10,
"min_similarity": 0.5
}
{
"success": true,
"query": "agent performance optimization",
"contexts": [
{
"content": "Performance optimization strategies...",
"metadata": {
"agent_id": "mindxagent",
"memory_type": "learning",
"similarity": 0.87
},
"doc_id": "memory_123"
}
],
"count": 5
}
POST /api/rage/memory/store
Content-Type: application/json
{
"agent_id": "mindxagent",
"memory_type": "interaction",
"content": {
"action": "code_optimization",
"result": "success",
"metrics": {"improvement": "25%"}
},
"context": {"session_id": "abc123"},
"tags": ["optimization", "performance"]
}
# Get context from semantic memory
context_memories = await mindxagent._query_rage_memories(
query="performance optimization strategies",
top_k=10
)
Store memory with automatic embedding
memory_id = await mindxagent.store_memory_via_rage(
memory_type="learning",
content={"strategy": "parallel_processing", "improvement": "40%"},
tags=["optimization", "performance"]
)
# Get memory feedback for context
memory_context = await mindxagent.get_memory_feedback(
context="resource optimization patterns"
)
Learn from resource patterns
improvements = await mindxagent.learn_from_resource_patterns()
-- Adjust IVFFlat index parameters
ALTER TABLE memory_embeddings SET (ivfflat.probes = 10);
-- Rebuild index for better performance
REINDEX INDEX idx_embeddings_vector;
# Async connection pool configuration
pool = psycopg2.pool.SimpleConnectionPool(
minconn=5,
maxconn=50,
host="localhost",
database="mindx_memory"
)
# Cache frequently used embeddings
embedding_cache = {}
if text not in embedding_cache:
embedding_cache[text] = model.encode(text)
# Test migration without making changes
python scripts/migrate_memories_to_postgres.py --dry-run --verbose
# Perform actual migration
python scripts/migrate_memories_to_postgres.py
# Enable dual-write during transition
config.set("memory.dual_write_mode", True)
Gradually migrate components
1. New memories go to both systems
2. Validate PostgreSQL performance
3. Switch read operations to PostgreSQL
4. Disable file-based storage
-- Count memories in both systems
SELECT COUNT() FROM memories;
SELECT COUNT() FROM memory_embeddings;
-- Validate embedding quality
SELECT memory_id, vector_dims(embedding) as dimensions
FROM memory_embeddings
LIMIT 10;
async def check_database_health():
try:
conn = await pool.getconn()
await conn.execute("SELECT 1")
pool.putconn(conn)
return True
except Exception as e:
logger.error(f"Database health check failed: {e}")
return False
-- Monitor query performance
EXPLAIN ANALYZE
SELECT memory_id, 1 - (embedding <=> '[0.1,0.2,...]') as similarity
FROM memory_embeddings
ORDER BY embedding <=> '[0.1,0.2,...]'
LIMIT 10;
-- Regular VACUUM and ANALYZE
VACUUM ANALYZE memory_embeddings;
-- Rebuild IVFFlat index periodically
REINDEX INDEX CONCURRENTLY idx_embeddings_vector;
# Monitor embedding distribution
def analyze_embedding_quality():
embeddings = get_all_embeddings()
norms = [np.linalg.norm(emb) for emb in embeddings]
# Check for zero vectors or outliers
zero_count = sum(1 for n in norms if n < 1e-6)
avg_norm = np.mean(norms)
return {
"zero_vectors": zero_count,
"average_norm": avg_norm,
"quality_score": "good" if zero_count == 0 else "needs_attention"
}
# Increase pool size
pool_config = {
"minconn": 10,
"maxconn": 50,
"max_overflow": 30
}
-- Check index usage
EXPLAIN SELECT * FROM memory_embeddings
ORDER BY embedding <=> '[0.1,0.2,...]' LIMIT 10;
-- Adjust ivfflat.probes
ALTER TABLE memory_embeddings SET (ivfflat.probes = 20);
# Use GPU acceleration
model = SentenceTransformer('all-MiniLM-L6-v2', device='cuda')
Implement batch processing
embeddings = model.encode(texts, batch_size=64, show_progress_bar=True)
query_memories_semantic(query, **kwargs)save_memory_with_embedding(memory_data)get_resource_correlated_memories(pattern, **kwargs)retrieve_context(query, **kwargs)store_memory(memory_data)get_retrieval_stats()pgvectorscale Memory Integration enables context-aware autonomous intelligence with enterprise-grade performance and semantic understanding.