Zack Saadioui
8/24/2024
1
2
bash
pip install langchain-chroma
1
2
3
4
python
import os
import getpass
os.environ['OPENAI_API_KEY'] = getpass.getpass('OpenAI API Key:')
1
2
python
db = Chroma.from_documents(documents, OpenAIEmbeddings())
1
2
3
4
python
query = "What did the president say regarding education?"
docs = db.similarity_search(query)
print(docs[0].page_content)
1
2
3
4
python
embedding_vector = OpenAIEmbeddings().embed_query(query)
docs = db.similarity_search_by_vector(embedding_vector)
print(docs[0].page_content)
1
2
3
4
5
python
query = "Tell me about the impact of AI on education"
founds_docs = await db.amax_marginal_relevance_search(query, k=3, fetch_k=5)
for i, doc in enumerate(found_docs):
print(f"{i + 1}.", doc.page_content, "\n")
Copyright © Arsturn 2024