-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_migration_query.py
More file actions
110 lines (84 loc) · 3.19 KB
/
test_migration_query.py
File metadata and controls
110 lines (84 loc) · 3.19 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import os
from dotenv import load_dotenv
from langgraph.graph import StateGraph, START, END
from langchain_core.messages import HumanMessage, AIMessage
from state import AgentState
from nodes import retrieve, grade_documents, generate, web_search
def create_rag_graph() -> StateGraph:
"""Create the Agentic RAG StateGraph with self-correction loop."""
# Initialize the graph
workflow = StateGraph(AgentState)
# Add nodes
workflow.add_node("retrieve", retrieve)
workflow.add_node("grade_documents", grade_documents)
workflow.add_node("generate", generate)
workflow.add_node("web_search", web_search)
# Add edges
workflow.add_edge(START, "retrieve")
workflow.add_edge("retrieve", "grade_documents")
# Conditional edge for self-correction loop
def decide_next_step(state: AgentState) -> str:
"""Determine next step based on document relevance."""
# If web search was already performed, go to generation to prevent infinite loop
if state.get("web_search_performed", False):
return "generate"
if state.get("is_relevant", False):
return "generate"
else:
return "web_search"
workflow.add_conditional_edges(
"grade_documents",
decide_next_step,
{
"generate": "generate",
"web_search": "web_search"
}
)
# Complete the loop
workflow.add_edge("web_search", "retrieve")
workflow.add_edge("generate", END)
return workflow.compile()
def main():
"""Test the 2026 Gemini migration efficiency query."""
# Load environment variables
load_dotenv()
# Create the graph
app = create_rag_graph()
print("Testing 2026 Gemini Migration Efficiency Query")
print("=" * 50)
# Test the specific query about 2026 migration efficiency
query = "What is the primary efficiency gain of 2026 Gemini migration?"
print(f"Query: {query}")
print("-" * 50)
# Initial state
initial_state = {
"messages": [HumanMessage(content=query)],
"documents": [],
"is_relevant": False,
"web_search_performed": False
}
# Run the graph
result = app.invoke(initial_state)
# Print results
print(f"Documents retrieved: {len(result['documents'])}")
print(f"Documents relevant: {result['is_relevant']}")
# Print final answer
print("\nFinal Answer:")
print("-" * 20)
for message in result["messages"]:
if isinstance(message, AIMessage):
print(message.content)
# Check for 25% latency reduction
final_answer = ""
for message in result["messages"]:
if isinstance(message, AIMessage):
final_answer = message.content.lower()
if "25%" in final_answer and "latency" in final_answer:
print("\n✅ SUCCESS: Answer correctly mentions 25% latency reduction!")
elif "25%" in final_answer:
print("\n⚠️ PARTIAL: Answer mentions 25% but not specifically latency reduction")
else:
print("\n❌ ISSUE: Answer does not mention 25% latency reduction")
print("=" * 50)
if __name__ == "__main__":
main()