Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to leverage Azure Open AI embeddings instead of Open AI embeddings in langchain framewrok #12

Open
kingafy opened this issue Jun 23, 2023 · 0 comments

Comments

@kingafy
Copy link

kingafy commented Jun 23, 2023

As there is a difference in the way we generate embeddings in Azure Open AI vs Open AI as we are not able to create bulk embeddings in single request through Azure Open AI. I have created Azure Open AI embeddings in the below way:-
from langchain.text_splitter import CharacterTextSplitter
#from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.create_documents(contents)
print(texts)
texts_new = [doc.page_content for doc in texts]

Print the extracted texts

list_docs=[]
for text in texts_new:
print(text)
list_docs.append(text)

import time
Embeddings_list=[]
for item in list_docs:
print(item)
while True:
try:
response = openai.Embedding.create(input=item, engine="text-embedding-ada-002")
embeddings = response['data'][0]['embedding']
Embeddings_list.append(embeddings)
break
except Exception as e:
print(e)
time.sleep(15)

How to use this Embedding_list to ingest into vector store and club it to QNA process as this way of embedding integration into the below process has no guided documentation

Create a vectorstore from documents

db = Chroma.from_documents(texts, embeddings)

Create retriever interface

retriever = db.as_retriever()

Create QA chain

qa = RetrievalQA.from_chain_type(llm=OpenAI(openai_api_key=openai_api_key), chain_type='stuff', retriever=retriever)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant