Refactored and moved all keys and configuration into .env files and provided samples
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import os
|
||||
|
||||
from typing import Tuple
|
||||
from langchain_community.vectorstores.azuresearch import AzureSearch
|
||||
from langchain_community.vectorstores.azuresearch import (
|
||||
AzureSearch,
|
||||
FIELDS_CONTENT,
|
||||
FIELDS_CONTENT_VECTOR,
|
||||
FIELDS_ID,
|
||||
FIELDS_METADATA,
|
||||
)
|
||||
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
|
||||
from dotenv import load_dotenv
|
||||
from uuid import uuid4
|
||||
@@ -32,6 +38,50 @@ embeddings: AzureOpenAIEmbeddings = AzureOpenAIEmbeddings(
|
||||
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
|
||||
)
|
||||
|
||||
try:
|
||||
from azure.search.documents.indexes.models import (
|
||||
SearchableField,
|
||||
SearchField,
|
||||
SearchFieldDataType,
|
||||
SimpleField,
|
||||
)
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Unable to import azure.search.documents. Please install with "
|
||||
"`pip install -U azure-search-documents`."
|
||||
) from e
|
||||
|
||||
fields = [
|
||||
SimpleField(
|
||||
name=FIELDS_ID,
|
||||
type=SearchFieldDataType.String,
|
||||
key=True,
|
||||
filterable=True,
|
||||
),
|
||||
SimpleField(
|
||||
name="company",
|
||||
type=SearchFieldDataType.String,
|
||||
key=False,
|
||||
filterable=True,
|
||||
),
|
||||
SearchableField(
|
||||
name=FIELDS_CONTENT,
|
||||
type=SearchFieldDataType.String,
|
||||
),
|
||||
SearchField(
|
||||
name=FIELDS_CONTENT_VECTOR,
|
||||
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
|
||||
searchable=True,
|
||||
vector_search_dimensions=None or len("Text"),
|
||||
vector_search_profile_name="myHnswProfile",
|
||||
),
|
||||
SearchableField(
|
||||
name=FIELDS_METADATA,
|
||||
type=SearchFieldDataType.String,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
# Specify additional properties for the Azure client such as the following https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md#configurations
|
||||
vector_store: AzureSearch = AzureSearch(
|
||||
azure_search_endpoint=os.getenv("VECTOR_STORE_ADDRESS"),
|
||||
@@ -40,6 +90,7 @@ vector_store: AzureSearch = AzureSearch(
|
||||
embedding_function=embeddings.embed_query,
|
||||
# Configure max retries for the Azure client
|
||||
additional_search_client_options={"retry_total": os.getenv("RETRY_TOTAL")},
|
||||
fields=fields,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user