File size: 880 Bytes
a7cba55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Shared state schema passed between every LangGraph node."""
from __future__ import annotations

from typing import Annotated, List, Optional, TypedDict

from langgraph.graph.message import add_messages


class RetrievedChunkDict(TypedDict):
    chunk_id: str
    text: str
    score: float
    metadata: dict


class RAGState(TypedDict, total=False):
    # Conversation
    messages: Annotated[list, add_messages]

    # Query understanding
    raw_query: str
    standalone_query: str  # history-aware, de-referenced query

    # Retrieval
    retrieved_chunks: List[RetrievedChunkDict]
    reranked_chunks: List[RetrievedChunkDict]

    # Generation
    draft_answer: str
    final_answer: str

    # Critique / evaluate loop
    is_satisfactory: bool
    critique_feedback: str
    refine_count: int
    max_refine_iterations: int

    # Observability
    trace: List[dict]