# Configure a search index
index_client = SearchIndexClient(
endpoint=search_service_endpoint, credential=credential)
fields = [
SimpleField(name="id", type=SearchFieldDataType.String),
SimpleField(name="vector_id", type=SearchFieldDataType.String, key=True),
SimpleField(name="url", type=SearchFieldDataType.String),
SearchableField(name="title", type=SearchFieldDataType.String),
SearchableField(name="text", type=SearchFieldDataType.String),
SearchField(name="title_vector", type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
searchable=True, vector_search_dimensions=1536, vector_search_configuration="my-vector-config"),
SearchField(name="content_vector", type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
searchable=True, vector_search_dimensions=1536, vector_search_configuration="my-vector-config"),
]
# Configure the vector search configuration
vector_search = VectorSearch(
algorithm_configurations=[
HnswVectorSearchAlgorithmConfiguration(
name="my-vector-config",
kind="hnsw",
parameters={
"m": 4,
"efConstruction": 400,
"efSearch": 500,
"metric": "cosine"
}
)
]
)
# Optional: configure semantic reranking by passing your title, keywords, and content fields
semantic_config = SemanticConfiguration(
name="my-semantic-config",
prioritized_fields=PrioritizedFields(
title_field=SemanticField(field_name="title"),
prioritized_keywords_fields=[SemanticField(field_name="url")],
prioritized_content_fields=[SemanticField(field_name="text")]
)
)
# Create the semantic settings with the configuration
semantic_settings = SemanticSettings(configurations=[semantic_config])
# Create the index
index = SearchIndex(name=index_name, fields=fields,
vector_search=vector_search, semantic_settings=semantic_settings)
result = index_client.create_or_update_index(index)
print(f'{result.name} created')