File size: 2,332 Bytes
5c4bfe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Debug the RAG service to see what's happening

"""
import os
import sys
import logging
from dotenv import load_dotenv
from qdrant_client import QdrantClient

# Setup logging
logging.basicConfig(level=logging.DEBUG)

# Load environment
load_dotenv()

# Import RAG service
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from services.rag_service import RAGService

# Initialize
api_key = os.getenv("OPENAI_API_KEY")
qdrant_url = os.getenv("QDRANT_URL")
qdrant_api_key = os.getenv("QDRANT_API_KEY")
collection_name = os.getenv("QDRANT_COLLECTION", "project_documents")

print(f"API Key: {api_key[:20]}..." if api_key else "No API key")
print(f"Qdrant URL: {qdrant_url}")
print(f"Collection: {collection_name}")

# Initialize Qdrant client
qdrant_host = os.getenv("QDRANT_HOST")
if qdrant_api_key and qdrant_host and "qdrant.io" in qdrant_host:
    print("\n✅ Using Qdrant Cloud")
    qdrant_client = QdrantClient(
        url=qdrant_host,
        api_key=qdrant_api_key,
        prefer_grpc=False
    )
else:
    print("\n✅ Using Local Qdrant (without Qdrant for testing)")
    # Don't initialize Qdrant for now - test without it
    qdrant_client = None
    print("⚠️ Qdrant disabled for testing - will use selected text only")

# Initialize RAG service
rag_service = RAGService(api_key, qdrant_client, collection_name)

# Test query
selected_text = """

Physical AI refers to artificial intelligence systems that interact with the physical world.

These systems use sensors to perceive their environment and actuators to take actions.

Examples include robots, self-driving cars, and drones.

"""

question = "What is Physical AI?"

print("\n=== Testing RAG Service ===")
print(f"Selected Text Length: {len(selected_text)} chars")
print(f"Question: {question}")

try:
    answer = rag_service.query_rag(selected_text, question)
    print(f"\n✅ Answer received:")
    print(f"Length: {len(answer)} chars")
    print(f"Content: {answer}")

    if "Is sawal ka jawab provided data me mojood nahi hai" in answer:
        print("\n❌ ERROR: Getting fallback message!")
        print("This means the RAG logic is failing somewhere.")
except Exception as e:
    print(f"\n❌ Error: {str(e)}")
    import traceback
    traceback.print_exc()