From 05967557cbd0b268109bbff43984ee4521709211 Mon Sep 17 00:00:00 2001 From: edvan_microsoft Date: Thu, 14 Nov 2024 10:25:46 +0100 Subject: [PATCH] addressed comments --- python/samples/concepts/memory/new_memory.py | 6 +++-- .../memory/azure_ai_search/utils.py | 23 +++++++++++-------- .../memory/redis/redis_collection.py | 14 ++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/python/samples/concepts/memory/new_memory.py b/python/samples/concepts/memory/new_memory.py index 0aaf9b9840e6..0f9f353d3471 100644 --- a/python/samples/concepts/memory/new_memory.py +++ b/python/samples/concepts/memory/new_memory.py @@ -54,11 +54,12 @@ class DataModelArray: deserialize_function=np.array, ), ] = None - other: str | None = None id: Annotated[str, VectorStoreRecordKeyField()] = field(default_factory=lambda: str(uuid4())) content: Annotated[ str, VectorStoreRecordDataField(has_embedding=True, embedding_property_name="vector", property_type="str") ] = "content1" + title: Annotated[str, VectorStoreRecordDataField(property_type="str", is_full_text_searchable=True)] = "title" + tag: Annotated[str, VectorStoreRecordDataField(property_type="str", is_filterable=True)] = "tag" return DataModelArray @@ -77,11 +78,12 @@ class DataModelList: property_type="float", ), ] = None - other: str | None = None id: Annotated[str, VectorStoreRecordKeyField()] = field(default_factory=lambda: str(uuid4())) content: Annotated[ str, VectorStoreRecordDataField(has_embedding=True, embedding_property_name="vector", property_type="str") ] = "content1" + title: Annotated[str, VectorStoreRecordDataField(property_type="str", is_full_text_searchable=True)] = "title" + tag: Annotated[str, VectorStoreRecordDataField(property_type="str", is_filterable=True)] = "tag" return DataModelList diff --git a/python/semantic_kernel/connectors/memory/azure_ai_search/utils.py b/python/semantic_kernel/connectors/memory/azure_ai_search/utils.py index fdec262f020c..6acd20cb18e1 100644 --- a/python/semantic_kernel/connectors/memory/azure_ai_search/utils.py +++ b/python/semantic_kernel/connectors/memory/azure_ai_search/utils.py @@ -148,18 +148,21 @@ def data_model_definition_to_azure_ai_search_index( try: algo_class, algo_params = INDEX_ALGORITHM_MAP[field.index_kind or "default"] except KeyError as e: - raise ServiceInitializationError(f"Error: {e} not found in INDEX_ALGORITHM_MAP.") from e + raise ServiceInitializationError(f"Error: {field.index_kind} not found in INDEX_ALGORITHM_MAP.") from e try: - search_algos.append( - algo_class( - name=algo_name, - parameters=algo_params( - metric=DISTANCE_FUNCTION_MAP[field.distance_function or "default"], - ), - ) - ) + distance_metric = DISTANCE_FUNCTION_MAP[field.distance_function or "default"] except KeyError as e: - raise ServiceInitializationError(f"Error: {e} not found in DISTANCE_FUNCTION_MAP.") from e + raise ServiceInitializationError( + f"Error: {field.distance_function} not found in DISTANCE_FUNCTION_MAP." + ) from e + search_algos.append( + algo_class( + name=algo_name, + parameters=algo_params( + metric=distance_metric, + ), + ) + ) return SearchIndex( name=collection_name, fields=fields, diff --git a/python/semantic_kernel/connectors/memory/redis/redis_collection.py b/python/semantic_kernel/connectors/memory/redis/redis_collection.py index 2f9bd2d2b4ee..f4f59a1ecded 100644 --- a/python/semantic_kernel/connectors/memory/redis/redis_collection.py +++ b/python/semantic_kernel/connectors/memory/redis/redis_collection.py @@ -467,18 +467,14 @@ def _serialize_dicts_to_store_models( def _deserialize_store_models_to_dicts( self, records: Sequence[dict[str, Any]], - keys: Sequence[str] | None = None, **kwargs: Any, ) -> Sequence[dict[str, Any]]: - key_field_name = self.data_model_definition.key_field_name - if keys is None: - if key_field_name in records[0]: - return records - raise MemoryConnectorException("Key field not found in records, and not supplied.") results = [] - for key, record in zip(keys, records): - record[self.data_model_definition.key_field_name] = self._unget_redis_key(key) - results.append(record) + key_field_name = self.data_model_definition.key_field_name + for record in records: + rec = record.copy() + rec[key_field_name] = self._unget_redis_key(record[key_field_name]) + results.append(rec) return results def _add_return_fields(self, query: TQuery, include_vectors: bool) -> TQuery: