feat: H-CITE + H-RET + H-DATA-LIFE — evidence references in ask_knowledge, knowledge retention ARQ cron job (daily 05:00), re-extraction hook on wiki.article.updated
Check Cross-Plugin Imports / check (push) Has been cancelled

This commit is contained in:
Agent Zero
2026-08-20 23:06:16 +02:00
parent adc86ad980
commit a9e7195b93
4 changed files with 104 additions and 9 deletions
+35 -8
View File
@@ -109,22 +109,48 @@ async def ask_knowledge(
# Search wiki articles for context
from app.plugins.builtins.unified_search.provider_registry import get_search_registry
registry = get_search_registry()
wiki_provider = registry.get("wiki_article")
evidence: list[dict[str, Any]] = []
context_parts = []
wiki_provider = registry.get("wiki_article")
if wiki_provider:
results = await wiki_provider._search_fts_filtered(
db=db, tsquery=question, tenant_id=tenant_id, limit=5, visible_ids=None
)
for r in results:
context_parts.append(f"Title: {r.get('title', '')}\nContent: {r.get('content', '')[:500]}")
snippet = (r.get("content", "") or "")[:300]
title = r.get("title", "")
context_parts.append(f"Title: {title}\nContent: {snippet}")
evidence.append({
"id": str(r.get("id", "")),
"source_type": "wiki_article",
"source_id": str(r.get("id", "")),
"title": title,
"snippet": snippet,
"score": float(r.get("rank", 0.0)),
"url": f"/wiki?article={r.get('slug', '')}",
})
# Search graph_rag for relationships
graph_provider = registry.get("graph_relationship")
if graph_provider:
results = await graph_provider._search_fts_filtered(
db=db, tsquery=question, tenant_id=tenant_id, limit=5, visible_ids=None
)
for r in results:
context_parts.append(f"Relationship: {r.get('source_type')} -> {r.get('relationship_type')} -> {r.get('target_type')}")
try:
results = await graph_provider._search_fts_filtered(
db=db, tsquery=question, tenant_id=tenant_id, limit=5, visible_ids=None
)
for r in results:
title = f"{r.get('source_type', '')}{r.get('relationship_type', '')}{r.get('target_type', '')}"
snippet = str(r.get("meta", ""))
context_parts.append(f"Relationship: {title}")
evidence.append({
"id": str(r.get("id", "")),
"source_type": "graph_relationship",
"source_id": str(r.get("id", "")),
"title": title,
"snippet": snippet,
"score": float(r.get("rank", 0.0)),
"url": None,
})
except Exception:
logger.warning("GraphRAG search failed in ask_knowledge", exc_info=True)
context = "\n\n".join(context_parts) if context_parts else "No knowledge base content found."
messages = [
{"role": "system", "content": f"You are a knowledge assistant. Answer based on this context:\n\n{context}"},
@@ -136,7 +162,8 @@ async def ask_knowledge(
)
return {
"answer": response.get("content", ""),
"evidence": context_parts[:3],
"evidence": evidence,
"sources_used": list(set(e["source_type"] for e in evidence)),
"cost_usd": response.get("cost_usd", 0.0),
}