-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple.py
More file actions
113 lines (98 loc) · 3.11 KB
/
test_simple.py
File metadata and controls
113 lines (98 loc) · 3.11 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
#!/usr/bin/env python3
"""
doredore - 簡単な動作テスト
このスクリプトは、ビルドされたライブラリが正しく動作するかテストします。
"""
print("=" * 60)
print("doredore - 動作テスト")
print("=" * 60)
print()
# Step 1: インポートテスト
print("1. モジュールのインポート...")
try:
from doredore import PyDoredore as Doredore
print(" ✅ インポート成功!")
except ImportError as e:
print(f" ❌ インポート失敗: {e}")
print()
print("注意: wheelファイルをインストールする必要があります:")
print(" pip3 install target/wheels/doredore-*.whl")
exit(1)
print()
# Step 2: 初期化テスト
print("2. Doredore の初期化...")
try:
rag = Doredore(
db_path="./test_knowledge.db",
model="bge-small-en-v1.5",
cache_dir=None
)
print(" ✅ 初期化成功!")
except Exception as e:
print(f" ❌ 初期化失敗: {e}")
exit(1)
print()
# Step 3: コレクション作成テスト
print("3. コレクション作成...")
try:
collection_id = rag.create_collection("test", "テストコレクション")
print(f" ✅ コレクション作成成功!(ID: {collection_id})")
except Exception as e:
print(f" ⚠️ コレクション作成: {e} (既に存在する可能性)")
print()
# Step 4: ドキュメント追加テスト
print("4. ドキュメント追加...")
try:
doc_id = rag.add_document(
content="これはテストドキュメントです。doredoreの動作確認用です。",
collection="test"
)
print(f" ✅ ドキュメント追加成功!(ID: {doc_id})")
except Exception as e:
print(f" ❌ ドキュメント追加失敗: {e}")
exit(1)
print()
# Step 5: 検索テスト
print("5. 検索テスト...")
try:
results = rag.search(
query="テスト",
collection="test",
top_k=3
)
print(f" ✅ 検索成功!({len(results)} 件の結果)")
if results:
for i, result in enumerate(results, 1):
print(f"\n 結果 {i}:")
print(f" スコア: {result.score:.3f}")
print(f" 内容: {result.content[:50]}...")
except Exception as e:
print(f" ❌ 検索失敗: {e}")
exit(1)
print()
# Step 6: エンリッチテスト
print("6. エンリッチ(RAGメイン機能)テスト...")
try:
enrich_result = rag.enrich(
query="doredoreについて教えて",
collection="test",
top_k=1
)
print(" ✅ エンリッチ成功!")
print()
print(" 生成されたコンテキスト:")
print(" " + "-" * 56)
print(" " + enrich_result.context[:100] + "...")
print(" " + "-" * 56)
except Exception as e:
print(f" ❌ エンリッチ失敗: {e}")
exit(1)
print()
print("=" * 60)
print("🎉 全てのテストが成功しました!")
print("=" * 60)
print()
print("次のステップ:")
print(" - examples/python/basic.py を実行")
print(" - examples/python/with_openai.py を実行(OpenAI API Key必要)")
print(" - examples/python/csv_import.py を実行")