-
I am using Microsoft.SemanticKernel 1.26 and Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL 1.26.0-preview. I am trying to insert records into the vector store but when I run the following code I get an error. Here is the code and TestRecord class for reference.
Here is the error that is caught when upserting
Am I doing something wrong here? Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
@westey-m - can you take a look at this? |
Beta Was this translation helpful? Give feedback.
-
Hi @dccrain, var jsonSerializerOptions = new JsonSerializerOptions
{
ReferenceHandler = ReferenceHandler.IgnoreCycles
};
CosmosClient client = new(
_cosmosEndpoint,
_cosmosKey,
new CosmosClientOptions() { UseSystemTextJsonSerializerWithOptions = jsonSerializerOptions });
Database database = client.GetDatabase(_cosmosdb);
var cosmosVectorStore = new AzureCosmosDBNoSQLVectorStore(database); |
Beta Was this translation helpful? Give feedback.
@dccrain, a further update. The default serializer used by the
CosmosClient
has a limitation in its ability to serialize certain types includingJsonObject
andReadOnlyMemory<float>
, so in order for theCosmosClient
to be used with Vectors and by extension the VectorStores implementation, its serializer has to be overridden. SettingUseSystemTextJsonSerializerWithOptions
does this overriding so thatSystem.Text.Json
is used instead of the built serializer.It is not actually required to set the
IgnoreCycles
setting either. The following works just as well.