fix КФП

This commit is contained in:
2026-06-16 10:07:06 +03:00
parent b1506f8695
commit 70910b82d2
3 changed files with 47 additions and 14 deletions
+18 -10
View File
@@ -10,7 +10,7 @@ from sqlalchemy import select
from sqlalchemy.orm import Session
from app.config import get_settings
from app.db.models import ChatSession, Document, DocumentChunk, MemoryFact
from app.db.models import ChatSession, Document, DocumentChunk
from app.rag import embeddings
from app.rag.chunker import chunk_text
from app.rag.store import (
@@ -22,25 +22,33 @@ from app.rag.store import (
)
async def index_memory_fact(fact: MemoryFact) -> None:
async def index_memory_fact(
*,
fact_id: int,
user_id: int,
content: str,
category: str,
importance: int,
active: bool = True,
) -> None:
settings = get_settings()
if not settings.rag_enabled or not fact.active:
if not settings.rag_enabled or not active:
return
vectors = await embeddings.embed_texts([fact.content])
vectors = await embeddings.embed_texts([content])
if not vectors:
return
upsert_points(
COLLECTION_FACTS,
[
qm.PointStruct(
id=int(fact.id),
id=int(fact_id),
vector=vectors[0],
payload={
"user_id": fact.user_id,
"fact_id": fact.id,
"category": fact.category,
"content": fact.content,
"importance": fact.importance,
"user_id": user_id,
"fact_id": fact_id,
"category": category,
"content": content,
"importance": importance,
},
)
],