This repository was archived by the owner on Mar 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_chroma.py
More file actions
77 lines (63 loc) · 2.69 KB
/
test_chroma.py
File metadata and controls
77 lines (63 loc) · 2.69 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
#!/usr/bin/env python3
"""
Testskript, um die ChromaDB-Verbindung und die Collections zu überprüfen
"""
import sys
import os
# Füge den src-Ordner zum Python-Pfad hinzu
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from src.chroma.client import ChromaDBClient
from src.core.service_config import ServiceConfig
def test_chroma_connection():
"""Testet die Verbindung zur ChromaDB und zeigt Collections an"""
print("Teste ChromaDB-Verbindung...")
# Verwende die Standard-Service-Konfiguration
config = ServiceConfig()
# Initialisiere den ChromaDB-Client
chroma_client = ChromaDBClient(
host=config.chroma_host,
port=config.chroma_port,
timeout=config.chroma_timeout
)
# Überprüfe Verbindung
print(f"Versuche, mit ChromaDB zu verbinden unter {config.chroma_host}:{config.chroma_port}...")
if chroma_client.health_check():
print("✓ ChromaDB-Verbindung erfolgreich hergestellt")
else:
print("✗ Keine Verbindung zur ChromaDB möglich")
return False
# Liste alle Collections auf
try:
collections = chroma_client.client.list_collections()
print(f"\nVorhandene Collections: {len(collections)}")
for col in collections:
count = col.count() if hasattr(col, 'count') else 'N/A'
print(f"- {col.name}: {count} Datensätze")
except Exception as e:
print(f"Fehler beim Abrufen der Collections: {e}")
# Erstelle eine Test-Collection
print(f"\nErstelle Test-Collection 'test_collection'...")
success = chroma_client.create_collection('test_collection')
if success:
print("✓ Test-Collection erfolgreich erstellt oder bereits vorhanden")
# Füge ein Test-Dokument hinzu
print("Füge Test-Dokument hinzu...")
try:
test_collection = chroma_client.get_or_create_collection('test_collection')
test_collection.add(
embeddings=[[0.1, 0.2, 0.3, 0.4, 0.5]], # Beispiel-Embedding
documents=["Dies ist ein Testdokument"],
metadatas=[{"test": "data", "source": "test_script"}],
ids=["test_id_1"]
)
print("✓ Test-Dokument erfolgreich hinzugefügt")
# Überprüfe den Inhalt der Collection
count = test_collection.count()
print(f"Anzahl Dokumente in 'test_collection': {count}")
except Exception as e:
print(f"✗ Fehler beim Hinzufügen des Test-Dokuments: {e}")
else:
print("✗ Fehler beim Erstellen der Test-Collection")
return True
if __name__ == "__main__":
test_chroma_connection()