File size: 1,106 Bytes
1f7ead8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import sys
import os

# Add project root to path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from backend.app.services.rag import generate_answer

def test_rag():
    print("Testing RAG Generation with Gemini...")
    
    query = "What causes backend crashes?"
    context_chunks = [
        {"doc_id": "doc1", "text": "Backend crashes are often caused by memory leaks and lack of resource isolation."},
        {"doc_id": "doc2", "text": "Using Docker with memory limits can prevent single container crashes from affecting the host."}
    ]
    
    try:
        answer = generate_answer(query, context_chunks)
        print("--- Generated Answer ---")
        print(answer)
        print("--- End Answer ---")
        
        if "Internal Error" in answer or "encountered an error" in answer:
            print("FAILED: RAG returned error.")
        else:
            print("SUCCESS: RAG generation working.")
            
    except Exception as e:
        print(f"EXCEPTION: {e}")

if __name__ == "__main__":
    test_rag()