From f37b3dc94ac9a4ea0e5dd1f043defd6fc8814602 Mon Sep 17 00:00:00 2001 From: John Aziz Date: Tue, 13 Feb 2024 15:18:26 +0200 Subject: [PATCH] Python: check if timestamp exists (#4977) ### Motivation and Context fix #4975 ### Description check if the key timestamp exists before setting it as it's optional ### Contribution Checklist - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone :smile: --- .../memory/azure_cosmosdb/mongo_vcore_store_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/connectors/memory/azure_cosmosdb/mongo_vcore_store_api.py b/python/semantic_kernel/connectors/memory/azure_cosmosdb/mongo_vcore_store_api.py index 2295d2a8d356..1c9c5c1b0604 100644 --- a/python/semantic_kernel/connectors/memory/azure_cosmosdb/mongo_vcore_store_api.py +++ b/python/semantic_kernel/connectors/memory/azure_cosmosdb/mongo_vcore_store_api.py @@ -101,7 +101,7 @@ async def get(self, collection_name: str, key: str, with_embedding: bool) -> Mem text=result["text"], description=result["description"], additional_metadata=result["metadata"], - timestamp=result["timestamp"], + timestamp=result.get("timestamp", None), ) async def get_batch(self, collection_name: str, keys: List[str], with_embeddings: bool) -> List[MemoryRecord]: @@ -117,7 +117,7 @@ async def get_batch(self, collection_name: str, keys: List[str], with_embeddings text=result["text"], description=result["description"], additional_metadata=result["metadata"], - timestamp=result["timestamp"], + timestamp=result.get("timestamp", None), ) for result in results ] @@ -163,7 +163,7 @@ async def get_nearest_matches( text=aggResult["document"]["text"], description=aggResult["document"]["description"], additional_metadata=aggResult["document"]["metadata"], - timestamp=aggResult["document"]["timestamp"], + timestamp=aggResult["document"].get("timestamp", None), ) if aggResult["similarityScore"] < min_relevance_score: continue