feat(rag): RAG scoping and context isolation controls
- Migration 0030: add conversations.rag_project_id (NULL=orphan-only, -1=all notes, positive=project), projects.auto_summary and projects.summary_updated_at - Three-value scope semantics thread from build_context() → semantic search and keyword fallback via orphan_only + effective_project_id - Project summarization background job (generate_project_summary, backfill_project_summaries) called via Ollama; triggered on project update and note saves (debounced 1h); runs at startup - New LLM tools: search_projects (SequenceMatcher scoring on title+description+auto_summary) and set_rag_scope (persists to DB, workspace-guarded, emits new_rag_scope in SSE done event) - execute_tool() accepts conv_id + workspace_project_id; generation_task passes both and captures scope changes for SSE done enrichment - Frontend: Conversation type gets rag_project_id; chat store adds ragProjectId computed + updateRagScope(); SSE done handler syncs scope - ChatView: replace sidebar ProjectSelector with a scope chip pill above the input bar, animated dropdown, pulse on model-driven scope change Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -139,11 +139,15 @@ async def cleanup_old_conversations(user_id: int, days: int) -> int:
|
||||
return len(result.fetchall())
|
||||
|
||||
|
||||
_UNSET = object()
|
||||
|
||||
|
||||
async def update_conversation(
|
||||
user_id: int,
|
||||
conversation_id: int,
|
||||
title: str | None = None,
|
||||
model: str | None = None,
|
||||
rag_project_id: object = _UNSET,
|
||||
) -> Conversation | None:
|
||||
async with async_session() as session:
|
||||
result = await session.execute(
|
||||
@@ -159,6 +163,8 @@ async def update_conversation(
|
||||
conv.title = title
|
||||
if model is not None:
|
||||
conv.model = model
|
||||
if rag_project_id is not _UNSET:
|
||||
conv.rag_project_id = rag_project_id # type: ignore[assignment]
|
||||
conv.updated_at = datetime.now(timezone.utc)
|
||||
await session.commit()
|
||||
await session.refresh(conv)
|
||||
|
||||
Reference in New Issue
Block a user