-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rag.py
More file actions
44 lines (37 loc) · 1.18 KB
/
Copy pathtest_rag.py
File metadata and controls
44 lines (37 loc) · 1.18 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
from app.core.rag import RAGSystem
import time
def test_rag():
print("--- Initializing RAG System ---")
rag = RAGSystem()
# 1. Define a "Training Example" (A known code smell)
bad_code = """
def calculate(a, b):
return a + b
"""
smell = "Missing Docstring"
fix = """
def calculate(a, b):
'''Adds two numbers.'''
return a + b
"""
print(f"--- Uploading Test Example: {smell} ---")
rag.upsert_code_example("test-id-001", bad_code, smell, fix)
# Wait a moment for Pinecone to index
print("Waiting 5 seconds for indexing...")
time.sleep(5)
# 2. Simulate a User Query (Similar but not identical code)
user_code = """
def subtract(x, y):
return x - y
"""
print("--- Searching for similar code ---")
results = rag.search_similar_code(user_code, top_k=1)
if results:
match = results[0]
print("✅ SUCCESS: Found similar example!")
print(f"Score: {match['score']}")
print(f"Retrieved Metadata (Smell Type): {match['metadata']['smell_type']}")
else:
print("❌ FAILED: No results found.")
if __name__ == "__main__":
test_rag()