-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretriver.py
More file actions
32 lines (25 loc) · 960 Bytes
/
Copy pathretriver.py
File metadata and controls
32 lines (25 loc) · 960 Bytes
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
import chromadb
from chromadb.utils import embedding_functions
# Initialize ChromaDB client and collection
client = chromadb.Client()
collection = client.create_collection(
name="study_notes",
embedding_function=embedding_functions.DefaultEmbeddingFunction()
)
# Sample documents — can be replaced with your own notes
documents = [
"Photosynthesis is the process by which plants convert light energy into chemical energy.",
"Chlorophyll absorbs sunlight to initiate photosynthesis.",
"Mitochondria are often called the powerhouse of the cell.",
"A noun is a word that represents a person, place, or thing."
]
collection.add(
documents=documents,
ids=[str(i) for i in range(len(documents))]
)
def retrieve_notes(query):
"""
Retrieves the top relevant notes from ChromaDB.
"""
results = collection.query(query_texts=[query], n_results=2)
return results["documents"][0]