Simplify AI memory pipeline
This commit is contained in:
@@ -17,10 +17,7 @@ from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
|
||||
from app.agents.memoir.narrative_agent import NarrativeAgent
|
||||
from app.agents.memoir.prompts import (
|
||||
format_evidence_chunks_for_prompt,
|
||||
format_narrative_user_content,
|
||||
)
|
||||
from app.agents.memoir.prompts import format_narrative_user_content
|
||||
from app.agents.memoir.story_route_agent import (
|
||||
APPEND_FIRST_CHAPTER_CATEGORIES,
|
||||
PLAN_BATCH_MAX_SEGMENTS,
|
||||
@@ -59,6 +56,7 @@ from app.features.memoir.repo import (
|
||||
mark_chapter_dirty_sync,
|
||||
reorder_chapter_story_links_by_life_order_sync,
|
||||
)
|
||||
from app.features.memory.evidence_format import format_evidence_chunks_for_prompt
|
||||
from app.features.story.models import Story, StoryVersion
|
||||
from app.features.story.sync_write import (
|
||||
append_story_version_sync,
|
||||
@@ -99,7 +97,7 @@ def _dialogue_lineage_dict_for_segment_ids(
|
||||
|
||||
def _evidence_link_ids(
|
||||
evidence: dict,
|
||||
) -> tuple[list[str], list[str], list[str], list[str]]:
|
||||
) -> tuple[list[str], list[str], list[str]]:
|
||||
"""从 MemoryService.retrieve 结果提取稳定 ID 列表。"""
|
||||
chunks: list[str] = []
|
||||
for c in evidence.get("relevant_chunks") or []:
|
||||
@@ -109,15 +107,11 @@ def _evidence_link_ids(
|
||||
for f in evidence.get("relevant_facts") or []:
|
||||
if isinstance(f, dict) and f.get("id"):
|
||||
facts.append(str(f["id"]))
|
||||
timelines: list[str] = []
|
||||
for e in evidence.get("timeline_hints") or []:
|
||||
if isinstance(e, dict) and e.get("id"):
|
||||
timelines.append(str(e["id"]))
|
||||
summaries: list[str] = []
|
||||
for s in evidence.get("relevant_summaries") or []:
|
||||
if isinstance(s, dict) and s.get("id"):
|
||||
summaries.append(str(s["id"]))
|
||||
return chunks, facts, timelines, summaries
|
||||
return chunks, facts, summaries
|
||||
|
||||
|
||||
def _story_prompt_meta_for_lineage(
|
||||
@@ -126,14 +120,13 @@ def _story_prompt_meta_for_lineage(
|
||||
memoir_correlation_id: str | None,
|
||||
top_k: int,
|
||||
) -> dict:
|
||||
c, f, t, s = _evidence_link_ids(evidence)
|
||||
c, f, s = _evidence_link_ids(evidence)
|
||||
return {
|
||||
"memoir_retrieval": {
|
||||
"correlation_id": memoir_correlation_id,
|
||||
"top_k": top_k,
|
||||
"chunk_ids": c,
|
||||
"fact_ids": f,
|
||||
"timeline_event_ids": t,
|
||||
"summary_ids": s,
|
||||
}
|
||||
}
|
||||
@@ -150,13 +143,13 @@ def _persist_story_lineage_sync(
|
||||
dialogue_lineage: dict | None = None,
|
||||
) -> None:
|
||||
"""写入 StoryEvidenceLink + 本版本 prompt_meta(可审计检索闭包)。"""
|
||||
c, f, t, s = _evidence_link_ids(evidence)
|
||||
c, f, s = _evidence_link_ids(evidence)
|
||||
replace_story_evidence_links_sync(
|
||||
session,
|
||||
story_id=story_id,
|
||||
chunk_ids=c,
|
||||
fact_ids=f,
|
||||
timeline_event_ids=t,
|
||||
timeline_event_ids=[],
|
||||
summary_ids=s,
|
||||
)
|
||||
version.prompt_meta = _story_prompt_meta_for_lineage(
|
||||
@@ -992,7 +985,6 @@ def run_story_pipeline_for_category_batch(
|
||||
"relevant_chunks": [],
|
||||
"relevant_summaries": [],
|
||||
"relevant_facts": [],
|
||||
"timeline_hints": [],
|
||||
"relevant_stories": [],
|
||||
}
|
||||
ev_elapsed = time.perf_counter() - _t_ev
|
||||
|
||||
Reference in New Issue
Block a user