File size: 834 Bytes
3b327ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_community.embeddings.sentence_transformer import (
    SentenceTransformerEmbeddings,
)
from langchain_community.vectorstores import Chroma

# create the open-source embedding function
embedding_function = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")

# load it into Chroma
db = Chroma(embedding_function=embedding_function, persist_directory="./chroma_db")

print("There are", db._collection.count(), " docs in the collection")

queries = [
  "Where is the Nowhere event?",
  "Give me some information about the toilets.",
  "What is consent?",
]

for query in queries:
  # query it
  docs = db.similarity_search(query)

  # print results
  print(f"\n\nQuery: {query}")
  print(f"Results: {len(docs)}")
  print(f"First result: {docs[0].page_content}")
  print(f"Second result: {docs[1].page_content}")