This commit is contained in:
Manoj Aggarwal 2026-01-21 09:47:17 -08:00
parent e3fe4b86df
commit ea6f6b3851
2 changed files with 12 additions and 35 deletions

View file

@ -12,7 +12,6 @@ about users across conversations.
from collections.abc import Sequence from collections.abc import Sequence
from alembic import op from alembic import op
from app.config import config from app.config import config
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.

View file

@ -10,7 +10,6 @@ Features:
""" """
import logging import logging
from datetime import UTC, datetime
from typing import Any from typing import Any
from uuid import UUID from uuid import UUID
@ -179,44 +178,23 @@ def create_save_memory_tool(
# Generate embedding for the memory # Generate embedding for the memory
embedding = config.embedding_model_instance.embed(content) embedding = config.embedding_model_instance.embed(content)
# Convert numpy array to list of Python floats for PostgreSQL # Create new memory using ORM
import numpy as np # The pgvector Vector column type handles embedding conversion automatically
if isinstance(embedding, np.ndarray): new_memory = UserMemory(
embedding_list = embedding.tolist() user_id=uuid_user_id,
else: search_space_id=search_space_id,
embedding_list = list(embedding) memory_text=content,
category=MemoryCategory(category), # Convert string to enum
# Create new memory using ORM with proper enum handling embedding=embedding, # Pass embedding directly (list or numpy array)
# Use the enum's value attribute directly
from sqlalchemy import text as sql_text
now = datetime.now(UTC)
# Use raw SQL with proper parameter binding for asyncpg
insert_sql = sql_text("""
INSERT INTO user_memories (user_id, search_space_id, memory_text, category, embedding, updated_at, created_at)
VALUES (:user_id, :search_space_id, :memory_text, CAST(:category AS memorycategory), :embedding, :updated_at, :created_at)
RETURNING id
""")
result = await db_session.execute(
insert_sql,
{
"user_id": uuid_user_id,
"search_space_id": search_space_id,
"memory_text": content,
"category": category, # Already lowercase string
"embedding": str(embedding_list), # Convert to string format for pgvector
"updated_at": now,
"created_at": now,
}
) )
new_memory_id = result.scalar_one()
db_session.add(new_memory)
await db_session.commit() await db_session.commit()
await db_session.refresh(new_memory)
return { return {
"status": "saved", "status": "saved",
"memory_id": new_memory_id, "memory_id": new_memory.id,
"memory_text": content, "memory_text": content,
"category": category, "category": category,
"message": f"I'll remember: {content}", "message": f"I'll remember: {content}",