-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathembeddings.py
More file actions
31 lines (22 loc) · 1.06 KB
/
embeddings.py
File metadata and controls
31 lines (22 loc) · 1.06 KB
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
30
31
import os
import openai
from dotenv import load_dotenv
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores.azuresearch import AzureSearch
from langchain_community.document_loaders.csv_loader import CSVLoader
from langchain_text_splitters import CharacterTextSplitter
load_dotenv('.env')
loader = CSVLoader("wine-ratings.csv")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000,
chunk_overlap=0)
split_docs =text_splitter.split_documents(documents)
print(os.getenv('SEARCH_SERVICE_NAME'))
embeddings = OpenAIEmbeddings()
# Connect and load to Azure Cognitive Search
azure_cog_search = AzureSearch(azure_search_endpoint=os.getenv('SEARCH_SERVICE_NAME'),
azure_search_key=os.getenv('SEARCH_API_KEY'),
index_name=os.getenv('SEARCH_INDEX_NAME'),
embedding_function=embeddings.embed_query)
#* Note this will take a while (84 minutes for me)
azure_cog_search.add_documents(documents=split_docs)