fix КФП
This commit is contained in:
+18
-10
@@ -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,
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
@@ -23,7 +23,14 @@ async def main() -> None:
|
||||
try:
|
||||
facts = db.scalars(select(MemoryFact).where(MemoryFact.active.is_(True))).all()
|
||||
for fact in facts:
|
||||
await index_memory_fact(fact)
|
||||
await index_memory_fact(
|
||||
fact_id=int(fact.id),
|
||||
user_id=int(fact.user_id),
|
||||
content=fact.content,
|
||||
category=fact.category,
|
||||
importance=int(fact.importance),
|
||||
active=bool(fact.active),
|
||||
)
|
||||
summaries = db.scalars(select(SessionSummary)).all()
|
||||
for row in summaries:
|
||||
if row.summary:
|
||||
|
||||
Reference in New Issue
Block a user