-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_plain_rag.py
More file actions
56 lines (43 loc) · 1.75 KB
/
Copy pathrun_plain_rag.py
File metadata and controls
56 lines (43 loc) · 1.75 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
from __future__ import annotations
import asyncio
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from app.agent import DemoDeps, run_grounded
from app.config import QUESTION
from app.retrievers import BaselineSurrealRetriever
RESET = "\033[0m"
BOLD = "\033[1m"
BLUE = "\033[94m"
CYAN = "\033[96m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
def style(text: str, *codes: str) -> str:
return "".join(codes) + text + RESET
async def main() -> None:
print(style("Plain Pydantic AI + SurrealDB RAG", BOLD, GREEN))
print(style("This is the baseline app without TurboAgents.", YELLOW))
retriever = BaselineSurrealRetriever()
print(style("Preparing baseline SurrealDB retriever...", YELLOW))
await retriever.prepare()
deps = DemoDeps(retriever=retriever)
started = time.perf_counter()
result = await run_grounded(QUESTION, deps=deps)
total_ms = (time.perf_counter() - started) * 1000
if not deps.metrics:
raise RuntimeError("The model did not call search_knowledge_base after two attempts.")
retrieval = deps.metrics[-1]
print(style("Question:", BOLD, CYAN), QUESTION)
print(style("Answer:", BOLD, CYAN), result.output)
print(style("Retriever mode:", BOLD, CYAN), retrieval.mode)
print(style("Retrieval time:", BOLD, CYAN), f"{retrieval.elapsed_ms:.2f} ms")
print(style("Agent total time:", BOLD, CYAN), f"{total_ms:.2f} ms")
print(style("Vector storage:", BOLD, CYAN), f"raw float32 only ({retrieval.raw_vector_bytes} bytes per vector)")
print(style("Top snippets:", BOLD, CYAN))
for snippet in retrieval.snippets:
print(f"- {snippet}")
if __name__ == "__main__":
asyncio.run(main())