-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_usage_chromadb.py
More file actions
44 lines (33 loc) · 1.16 KB
/
Copy pathexample_usage_chromadb.py
File metadata and controls
44 lines (33 loc) · 1.16 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
import chromadb
from sentence_transformers import SentenceTransformer
from smallevals import SmallEvalsVDBConnection, evaluate_retrievals
n_chunks = 298
def main():
CHROMADB_DIR = "./tests/assets/test_vdbs/chroma"
COLLECTION_NAME = None
EMBEDDING_MODEL = "intfloat/e5-small-v2"
print("=" * 60)
print("ChromaDB Retrieval Evaluation")
print("=" * 60)
embedding = SentenceTransformer(EMBEDDING_MODEL)
chroma_client = chromadb.PersistentClient(path=CHROMADB_DIR)
if COLLECTION_NAME is None:
collections = chroma_client.list_collections()
COLLECTION_NAME = "paragraphs"
smallevals_vdb = SmallEvalsVDBConnection(
connection=chroma_client,
collection=COLLECTION_NAME,
embedding=embedding
)
print(f"Connected to ChromaDB collection: {COLLECTION_NAME}")
smallevals_result = evaluate_retrievals(
connection=smallevals_vdb,
top_k=10,
n_chunks=n_chunks,
device=None,
results_folder=None
)
print(f"\nResults saved to: {smallevals_result['results_path']}")
return smallevals_result
if __name__ == "__main__":
main()