OpenAI or OpenAIos.environ["OPENAI_API_TYPE"] = "azure"os.environ["OPENAI_API_BASE"] = "YOUR_OPENAI_ENDPOINT"os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"os.environ["OPENAI_API_VERSION"] = "2023-05-15"model: str = "text-embedding-ada-002"Configure vector store settings‚ÄãSet up the vector store settings using environment variables:vector_store_address: str = "YOUR_AZURE_SEARCH_ENDPOINT"vector_store_password: str = "YOUR_AZURE_SEARCH_ADMIN_KEY"Create embeddings and vector store instances‚ÄãCreate instances of the OpenAIEmbeddings and AzureSearch classes:embeddings: OpenAIEmbeddings = OpenAIEmbeddings(deployment=model, chunk_size=1)index_name: str = "langchain-vector-demo"vector_store: AzureSearch = AzureSearch(    azure_search_endpoint=vector_store_address,    azure_search_key=vector_store_password,    index_name=index_name,    embedding_function=embeddings.embed_query,)Insert text and embeddings into vector store‚ÄãAdd texts and metadata from the JSON data to the vector store:from langchain.document_loaders import TextLoaderfrom langchain.text_splitter import CharacterTextSplitterloader = TextLoader("../../modules/state_of_the_union.txt", encoding="utf-8")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)vector_store.add_documents(documents=docs)Perform a vector similarity search‚ÄãExecute a pure vector similarity search using the similarity_search() method:# Perform a similarity searchdocs = vector_store.similarity_search(    query="What did the president say about Ketanji Brown Jackson",    k=3,    search_type="similarity",)print(docs[0].page_content)    Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you‚Äôre at it, pass the Disclose Act so Americans can know who is funding our elections.         Tonight, I‚Äôd like to honor someone who has dedicated his life to serve this country: Justice Stephen
Azure Cognitive Search (formerly known as Azure Search) is a cloud search service that gives developers infrastructure, APIs, and tools for building a rich search experience over private, heterogeneous content in web, mobile, and enterprise applications.
Azure Cognitive Search (formerly known as Azure Search) is a cloud search service that gives developers infrastructure, APIs, and tools for building a rich search experience over private, heterogeneous content in web, mobile, and enterprise applications. ->: OpenAI or OpenAIos.environ["OPENAI_API_TYPE"] = "azure"os.environ["OPENAI_API_BASE"] = "YOUR_OPENAI_ENDPOINT"os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"os.environ["OPENAI_API_VERSION"] = "2023-05-15"model: str = "text-embedding-ada-002"Configure vector store settings‚ÄãSet up the vector store settings using environment variables:vector_store_address: str = "YOUR_AZURE_SEARCH_ENDPOINT"vector_store_password: str = "YOUR_AZURE_SEARCH_ADMIN_KEY"Create embeddings and vector store instances‚ÄãCreate instances of the OpenAIEmbeddings and AzureSearch classes:embeddings: OpenAIEmbeddings = OpenAIEmbeddings(deployment=model, chunk_size=1)index_name: str = "langchain-vector-demo"vector_store: AzureSearch = AzureSearch(    azure_search_endpoint=vector_store_address,    azure_search_key=vector_store_password,    index_name=index_name,    embedding_function=embeddings.embed_query,)Insert text and embeddings into vector store‚ÄãAdd texts and metadata from the JSON data to the vector store:from langchain.document_loaders import TextLoaderfrom langchain.text_splitter import CharacterTextSplitterloader = TextLoader("../../modules/state_of_the_union.txt", encoding="utf-8")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)vector_store.add_documents(documents=docs)Perform a vector similarity search‚ÄãExecute a pure vector similarity search using the similarity_search() method:# Perform a similarity searchdocs = vector_store.similarity_search(    query="What did the president say about Ketanji Brown Jackson",    k=3,    search_type="similarity",)print(docs[0].page_content)    Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you‚Äôre at it, pass the Disclose Act so Americans can know who is funding our elections.         Tonight, I‚Äôd like to honor someone who has dedicated his life to serve this country: Justice Stephen