-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_search.py
More file actions
68 lines (55 loc) · 2.08 KB
/
test_search.py
File metadata and controls
68 lines (55 loc) · 2.08 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
#!/usr/bin/env python3
"""
Test script to verify semantic search is working after fixing embeddings
"""
import sys
import os
sys.path.append('.')
# Mock the missing gradio module to avoid import errors
class MockGradio:
def __getattr__(self, name):
return lambda *args, **kwargs: None
sys.modules['gradio'] = MockGradio()
from note_graph import NoteGraph
def main():
print("🔍 Testing semantic search functionality...")
try:
# Initialize NoteGraph
ng = NoteGraph()
print('✅ NoteGraph initialized successfully')
# Initialize embedding model for sentence transformers
print('🧠 Initializing sentence transformer model...')
ng.init_embedding_model(use_openai=False)
print('✅ Embedding model initialized')
# Test semantic search
print('\n🔎 Testing semantic search for "AI"...')
results = ng.semantic_search('AI', limit=3)
print(f'🎯 Found {len(results)} results')
if results:
print('\n📋 Search Results:')
for i, result in enumerate(results, 1):
title = result.get('title', 'Unknown')
score = result.get('score', 0)
print(f'{i}. {title} (similarity: {score:.3f})')
else:
print('❌ No results found')
# Test another search
print('\n🔎 Testing semantic search for "cooking"...')
results = ng.semantic_search('cooking', limit=2)
print(f'🎯 Found {len(results)} results')
if results:
print('\n📋 Search Results:')
for i, result in enumerate(results, 1):
title = result.get('title', 'Unknown')
score = result.get('score', 0)
print(f'{i}. {title} (similarity: {score:.3f})')
print('\n✅ Semantic search is working correctly!')
return True
except Exception as e:
print(f'❌ Error testing search: {e}')
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)