Skip to content

Commit

Permalink
fix the bug on vector_search_profile default(this profile did not exi…
Browse files Browse the repository at this point in the history
…st) and add the possibility to choose language_analyzer of searchable fields, now on v0.10.3 format (run-llama#10675)
  • Loading branch information
ryanrib14 authored Feb 13, 2024
1 parent bf0b0c5 commit f4bcb31
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ def _create_index(self, index_name: Optional[str]) -> None:
SearchableField(
name=self._field_mapping["chunk"],
type="Edm.String",
analyzer_name="en.microsoft",
analyzer_name=self.language_analyzer,
),
SearchField(
name=self._field_mapping["embedding"],
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
searchable=True,
vector_search_dimensions=self.embedding_dimensionality,
vector_search_profile_name="default",
vector_search_profile_name=self.vector_profile_name,
),
SimpleField(name=self._field_mapping["metadata"], type="Edm.String"),
SimpleField(
Expand Down Expand Up @@ -243,6 +243,10 @@ def __init__(
] = None,
index_management: IndexManagement = IndexManagement.NO_VALIDATION,
embedding_dimensionality: int = 1536,
vector_algorithm_type: str = "exhaustiveKnn",
# If we have content in other languages, it is better to enable the language analyzer to be adjusted in searchable fields.
# https://learn.microsoft.com/en-us/azure/search/index-add-language-analyzers
language_analyzer: str = "en.lucene",
**kwargs: Any,
) -> None:
# ruff: noqa: E501
Expand Down Expand Up @@ -306,6 +310,16 @@ def __init__(
self._search_client: SearchClient = cast(SearchClient, None)
self.embedding_dimensionality = embedding_dimensionality

if vector_algorithm_type == "exhaustiveKnn":
self.vector_profile_name = "myExhaustiveKnnProfile"
elif vector_algorithm_type == "hnsw":
self.vector_profile_name = "myHnswProfile"
else:
raise ValueError(
"Only 'exhaustiveKnn' and 'hnsw' are supported for vector_algorithm_type"
)

self.language_analyzer = language_analyzer
# Validate search_or_index_client
if search_or_index_client is not None:
if isinstance(search_or_index_client, SearchIndexClient):
Expand Down

0 comments on commit f4bcb31

Please sign in to comment.