-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_rag.py
More file actions
115 lines (93 loc) · 3.75 KB
/
Copy pathdebug_rag.py
File metadata and controls
115 lines (93 loc) · 3.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
from langchain_chroma import Chroma
from get_embedding_function import get_embedding_function
# Direct paths without config
CHROMA_PATH = "chroma1"
DATA_PATH = "data"
EMBEDDING_MODEL = "all-mpnet-base-v2"
def debug_rag_database():
"""Debug what's actually in your RAG database"""
print("=" * 80)
print("RAG DATABASE DEBUGGING")
print("=" * 80)
# Check if database exists
if not os.path.exists(CHROMA_PATH):
print(f"❌ Database not found at: {CHROMA_PATH}")
return
print(f"✅ Database found at: {CHROMA_PATH}")
# Check database contents
try:
embedding_function = get_embedding_function(EMBEDDING_MODEL)
db = Chroma(persist_directory=CHROMA_PATH, embedding_function=embedding_function)
# Get all documents
all_docs = db.get()
print(f"📊 Total documents in database: {len(all_docs['ids'])}")
if len(all_docs['ids']) == 0:
print("❌ Database is empty!")
return
# Check content
print("\n📄 SAMPLE DOCUMENTS:")
for i in range(min(5, len(all_docs['documents']))):
doc_content = all_docs['documents'][i]
metadata = all_docs['metadatas'][i] if all_docs['metadatas'] else {}
print(f"\nDocument {i+1}:")
print(f" Source: {metadata.get('source', 'Unknown')}")
print(f" Content (first 200 chars): {doc_content[:600]}...")
# Check for our target content
content_lower = doc_content.lower()
has_transformer = 'transformer' in content_lower
has_gpt = 'gpt' in content_lower or 'gpt-3' in content_lower
has_vit = 'vision transformer' in content_lower or 'vit' in content_lower
print(f" Contains 'transformer': {has_transformer}")
print(f" Contains 'gpt': {has_gpt}")
print(f" Contains 'vision transformer': {has_vit}")
# Test retrieval
print("\n🔍 TESTING RETRIEVAL:")
test_queries = [
"transformer",
"GPT-3",
"attention mechanism",
"BLEU score"
]
for query in test_queries:
results = db.similarity_search(query, k=3)
print(f"\nQuery: '{query}' → {len(results)} results")
if results:
print(f" Best match: {results[0].page_content[:100]}...")
else:
print(" No results found")
except Exception as e:
print(f"❌ Error accessing database: {e}")
def check_pdf_files():
"""Check if PDF files exist and are readable"""
print("\n" + "=" * 80)
print("PDF FILES CHECK")
print("=" * 80)
expected_files = [
"attention_is_all_you_need.pdf",
"gpt3_paper.pdf",
"vision_transformer.pdf"
]
if not os.path.exists(DATA_PATH):
print(f"❌ Data directory not found: {DATA_PATH}")
return
for filename in expected_files:
filepath = os.path.join(DATA_PATH, filename)
if os.path.exists(filepath):
size = os.path.getsize(filepath)
print(f"✅ {filename}: {size:,} bytes")
else:
print(f"❌ {filename}: NOT FOUND")
# List all files in data directory
print(f"\nAll files in {DATA_PATH}:")
try:
for file in os.listdir(DATA_PATH):
filepath = os.path.join(DATA_PATH, file)
if os.path.isfile(filepath):
size = os.path.getsize(filepath)
print(f" {file}: {size:,} bytes")
except Exception as e:
print(f"Error listing files: {e}")
if __name__ == "__main__":
check_pdf_files()
debug_rag_database()