mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
ruff
This commit is contained in:
parent
e3fe4b86df
commit
ea6f6b3851
2 changed files with 12 additions and 35 deletions
|
|
@ -12,7 +12,6 @@ about users across conversations.
|
|||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
|
||||
from app.config import config
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ Features:
|
|||
"""
|
||||
|
||||
import logging
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
|
|
@ -179,44 +178,23 @@ def create_save_memory_tool(
|
|||
# Generate embedding for the memory
|
||||
embedding = config.embedding_model_instance.embed(content)
|
||||
|
||||
# Convert numpy array to list of Python floats for PostgreSQL
|
||||
import numpy as np
|
||||
if isinstance(embedding, np.ndarray):
|
||||
embedding_list = embedding.tolist()
|
||||
else:
|
||||
embedding_list = list(embedding)
|
||||
|
||||
# Create new memory using ORM with proper enum handling
|
||||
# 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,
|
||||
}
|
||||
# Create new memory using ORM
|
||||
# The pgvector Vector column type handles embedding conversion automatically
|
||||
new_memory = UserMemory(
|
||||
user_id=uuid_user_id,
|
||||
search_space_id=search_space_id,
|
||||
memory_text=content,
|
||||
category=MemoryCategory(category), # Convert string to enum
|
||||
embedding=embedding, # Pass embedding directly (list or numpy array)
|
||||
)
|
||||
new_memory_id = result.scalar_one()
|
||||
|
||||
db_session.add(new_memory)
|
||||
await db_session.commit()
|
||||
await db_session.refresh(new_memory)
|
||||
|
||||
return {
|
||||
"status": "saved",
|
||||
"memory_id": new_memory_id,
|
||||
"memory_id": new_memory.id,
|
||||
"memory_text": content,
|
||||
"category": category,
|
||||
"message": f"I'll remember: {content}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue