Geoffrey Kip commited on
Commit
ba94c6c
·
1 Parent(s): 122cdca

Test: Add RAG performance test script

Browse files
Files changed (1) hide show
  1. scripts/test_rag_perf.py +40 -0
scripts/test_rag_perf.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import time
3
+ import sys
4
+ import os
5
+ from dotenv import load_dotenv
6
+
7
+ # Add project root to path
8
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
9
+
10
+ from modules.tools import search_trials
11
+ from modules.utils import setup_llama_index
12
+
13
+ def test_rag_performance():
14
+ load_dotenv()
15
+
16
+ # Ensure LLM is set up (needed for expand_query if used, though search_trials handles it)
17
+ setup_llama_index()
18
+
19
+ query = "immunotherapy for lung cancer"
20
+ print(f"🚀 Starting RAG Search for: '{query}'")
21
+
22
+ start_time = time.time()
23
+ try:
24
+ # LangChain tools must be invoked with a dict
25
+ results = search_trials.invoke({"query": query})
26
+ end_time = time.time()
27
+
28
+ duration = end_time - start_time
29
+ print(f"✅ Search completed in {duration:.2f} seconds.")
30
+ print(f"📄 Result length: {len(results)} chars")
31
+ print("--- Preview ---")
32
+ print(results[:500] + "...")
33
+
34
+ except Exception as e:
35
+ print(f"❌ Search failed: {e}")
36
+ import traceback
37
+ traceback.print_exc()
38
+
39
+ if __name__ == "__main__":
40
+ test_rag_performance()