File size: 386 Bytes
bb4e28f
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import chromadb

client = chromadb.Client()
collection = client.get_or_create_collection("finsightx_kb")

def add_to_db(doc_id: str, text: str, embedding):
    collection.add(ids=[doc_id], documents=[text], embeddings=[embedding])

def query(text: str, embed_fn) -> dict:
    query_embedding = embed_fn(text)
    return collection.query(query_embeddings=[query_embedding], n_results=3)