semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Bug: 401 Unauthorized (Vertex AI and Weaviate)

Open heinsenberg82 opened this issue 1 year ago • 1 comments

I keep receiving the same error on my code:

Microsoft.SemanticKernel.HttpOperationException: Response status code does not indicate success: 401 (Unauthorized).
 ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Microsoft.SemanticKernel.Http.HttpClientExtensions.SendWithSuccessCheckAsync(HttpClient client, HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.SemanticKernel.Http.HttpClientExtensions.SendWithSuccessCheckAsync(HttpClient client, HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Http.HttpClientExtensions.SendWithSuccessCheckAsync(HttpClient client, HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Connectors.Weaviate.WeaviateMemoryStore.ExecuteHttpRequestAsync(HttpRequestMessage request, CancellationToken cancel)
   at Microsoft.SemanticKernel.Connectors.Weaviate.WeaviateMemoryStore.DoesCollectionExistAsync(String collectionName, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SaveInformationAsync(String collection, String text, String id, String description, String additionalMetadata, Kernel kernel, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in D:\code\Meu-Aluguel\Api\Program.cs:line 32
   at Program.<Main>(String[] args)

My code:

var weviateApiKey = "weaviate-admin-api-key";
var collection = "Test_Collection";
WeaviateMemoryStore memoryStore = new("https://my-endpoint.c0.us-east1.gcp.weaviate.cloud", weviateApiKey);

var projectId = "my-project-id";
var modelId = "gemini-1.5-pro-001";
var location = "us-central1";

var gloudAccessToken = "gcloud-access-token"; // I copied this directly from the command "gcloud auth print-access-token", just to be sure 

ITextEmbeddingGenerationService textEmbeddingService = new VertexAITextEmbeddingGenerationService("text-multilingual-embedding-002", gcloudAccessToken, location, projectId);

var memory = new SemanticTextMemory(memoryStore, textEmbeddingService);
await memory.SaveInformationAsync(collection, "My name is John", Guid.NewGuid().ToString()); // <-- the Exception is thrown on this line

I've already made sure that I have all the necessary permissions on the Google Cloud and AI Vertex API, so much so that I can generate embeddings via curl. I just can't generate the embeddings programmatically.

Also, this is my collection on Weaviate:

image

I can't identify what I would supposedly be doing wrong.

heinsenberg82 avatar Sep 21 '24 16:09 heinsenberg82

The Weaviate documentation (https://weaviate.io/developers/weaviate/model-providers/google/embeddings) says that, for the integration with Vertex AI to work, the Vertex AI API key must be passed in the request header in the X-Google-Vertex-Api-Key field. Is the library configured to do this?

heinsenberg82 avatar Sep 22 '24 13:09 heinsenberg82

Hi @heinsenberg82 we have introduced new VectorData connectors to replace the experimental Memory functionality. Our plan is to mark the current experimental Memory functionality as obsolete and we are encouraging developer to switch to using the VectorData functionality.

Here are some links to help you to get started:

  • https://github.com/markwallace-microsoft/semantic-kernel/tree/main/dotnet/samples/GettingStartedWithVectorStores
  • https://learn.microsoft.com/en-us/semantic-kernel/concepts/vector-store-connectors/?pivots=programming-language-csharp
  • https://learn.microsoft.com/en-us/semantic-kernel/concepts/vector-store-connectors/code-samples?pivots=programming-language-csharp

markwallace-microsoft avatar Nov 07 '24 08:11 markwallace-microsoft

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Apr 03 '25 02:04 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Apr 26 '25 02:04 github-actions[bot]