30 lines
574 B
Python
30 lines
574 B
Python
import chromadb
|
|
|
|
settings = chromadb.Settings(allow_reset=True)
|
|
client = chromadb.PersistentClient(path="./chroma",settings=settings)
|
|
coll = client.get_or_create_collection(name="test", metadata={"chapter": 1})
|
|
|
|
coll.upsert(
|
|
ids=["id1"],
|
|
documents=["doc1"],
|
|
metadatas=[ { "chapter": 1} ],
|
|
embeddings=[ [1] ]
|
|
)
|
|
|
|
coll.upsert(
|
|
ids=["id2"],
|
|
documents=["doc2"],
|
|
metadatas=[ { "chapter": 1} ],
|
|
embeddings=[ [1] ]
|
|
)
|
|
|
|
|
|
results = coll.query(
|
|
query_embeddings=[[1]],
|
|
#include=["documents"]
|
|
)
|
|
|
|
chromadb.QueryResult
|
|
print(results)
|
|
client.reset()
|