microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.53k stars 3.18k forks source link

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

Open heinsenberg82 opened 1 week ago

heinsenberg82 commented 1 week ago

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 commented 1 week ago

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?