Fix: Embeddings Indexing: `nil` user error in embeddings client

What does this MR do and why?

In Resolve "Pass organization_id in the headers to... (!231121 - merged), the Gitlab::Llm::Embeddings::Client was updated to pass an organization_id header in the request. This organization_id is taken from user.governing_namespace&.organization_id. However, the user value is always nil for the Code Embeddings Indexing process (the user is only passed for searching), so this call is causing NoMethodErrors in the indexing pipeline. See error logs

This MR fixes the issue by adding safe-navigation to the user&.governing_namespace. This also adds test to make it clear that this client allows nil users.

References

N/A

Screenshots or screen recordings

N/A

How to set up and validate locally

Run embeddings generation without passing in a user object. It should not raise an error.

::Ai::ActiveContext::Collections::Code.current_indexing_embedding_model.generate_embeddings(["test content"])

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Pam Artiaga

Merge request reports

Loading