meilisearch-rust icon indicating copy to clipboard operation
meilisearch-rust copied to clipboard

Add headers to Embedder settings

Open pacifistes opened this issue 2 months ago • 0 comments

Description Hello, it missing the headers field in the Embedder that is describe in the documentation to handle some rest embedding. Here is an example below:

Basic example I would add

/// A JSON value representing the headers Meilisearch expects from the remote embedder
#[serde(skip_serializing_if = "Option::is_none")]
pub headers: Option<HashMap<String, String>>,

in order to handle some rest embedding like gemini:

let task = movie_index
    .set_embedders(&HashMap::from([(
        String::from("gemini-embedder-with-rest"),
        Embedder {
            source: EmbedderSource::Rest,
            url: Some(String::from("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent")),
            request: Some(json!({
                "model": "models/gemini-embedding-001",
                "content": {"parts":[{"text": "{{text}}"}]},
            })),
            response: Some(json!({
                "embedding": {
                    "values": "{{embedding}}"
                }
            })),
            document_template: Some(String::from(
                "Title: {{doc.title}}. Genres: {{doc.genres}}. Overview: {{doc.overview}}. Release date: {{doc.release_date}}."
            )),
            headers: Some(HashMap::from([
                (String::from("x-goog-api-key"), env::var("GEMINI_API_KEY").unwrap()),
            ])),
            ..Default::default()
        },
    )])).await.unwrap();

I can prepare the pull request if you agree.

pacifistes avatar Oct 20 '25 17:10 pacifistes