trustgraph/trustgraph-base/trustgraph/schema/services/prompt.py
Cyber MacGeddon 1346cbebb4 feat: replace LLM edge scoring with cross-encoder reranker in GraphRAG
Replace the three-prompt LLM scoring pipeline (kg-edge-scoring,
kg-edge-reasoning, kg-edge-selection) with a cross-encoder reranker
service backed by FlashRank. The new hop_and_filter() method performs
iterative graph traversal with semantic scoring at each hop, replacing
the previous follow_edges/get_subgraph approach.

- Add reranker service (trustgraph-base client/service, FlashRank processor)
- Add gateway dispatch for reranker via API and WebSocket
- Rewrite GraphRAG pipeline: hop_and_filter() with per-hop cross-encoder scoring
- Remove kg_prompt() and edge_score_limit from prompt client
- Update provenance: add tg:EdgeSelection type, tg:concept, tg:score predicates
- Update CLIs (tg-invoke-graph-rag, tg-show-explain-trace) for new metadata
- Add tg-invoke-reranker CLI tool
- Add tech spec and UX developer guidance
- Update all unit and integration tests
2026-06-30 14:26:12 +01:00

38 lines
901 B
Python

from dataclasses import dataclass, field
from ..core.primitives import Error
############################################################################
# Prompt services, abstract the prompt generation
@dataclass
class PromptRequest:
id: str = ""
# JSON encoded values
terms: dict[str, str] = field(default_factory=dict)
# Streaming support (default false for backward compatibility)
streaming: bool = False
@dataclass
class PromptResponse:
# Error case
error: Error | None = None
# Just plain text
text: str = ""
# JSON encoded
object: str = ""
# Indicates final message in stream
end_of_stream: bool = False
# Token usage from the underlying text completion
in_token: int | None = None
out_token: int | None = None
model: str | None = None
############################################################################