---
title: "EmbeddingService"
manual: "TYPO3 LLM Extension"
version: "0.35"
permalink: "https://docs.typo3.org/permalink/netresearch/nr-llm:api-embedding-service@0.35"
source: "Api/EmbeddingService.rst"
modified: "2026-09-16T22:09:16+00:00"
---

# EmbeddingService

-   **class EmbeddingService**

    -   *Fully qualified name:* `\Netresearch\NrLlm\Service\Feature\EmbeddingService`

    Text-to-vector conversion with caching and similarity operations.

    -   **embed(string $text, ?EmbeddingOptions $options = null) : array**

        Generate embedding vector for text (cached).

        -   *param string $text:* The text to embed
        -   *param ?EmbeddingOptions $options:* Optional config

        *Returns:* array\<float> Vector representation

    -   **embedFull(string $text, ?EmbeddingOptions $options = null) : EmbeddingResponse**

        Generate embedding with full response metadata.

        -   *param string $text:* The text to embed
        -   *param ?EmbeddingOptions $options:* Optional config

        *Returns:* EmbeddingResponse

    -   **embedBatch(array $texts, ?EmbeddingOptions $options = null) : array**

        Generate embeddings for multiple texts.

        -   *param array $texts:* Array of texts
        -   *param ?EmbeddingOptions $options:* Optional config

        *Returns:* array\<array\<float>> Array of vectors

    -   **embedForConfiguration(string $text, LlmConfiguration $configuration, ?EmbeddingOptions $options = null) : array**

        Generate embedding vector for text against a specific LLM
        configuration, so the configuration's provider/model drive the
        call and per-configuration budgets and cost attribution apply.

        -   *param string $text:* The text to embed
        -   *param LlmConfiguration $configuration:*

            The
            configuration record to resolve provider/model from

        -   *param ?EmbeddingOptions $options:* Optional config

        *Returns:* array\<float> Vector representation

    -   **embedBatchForConfiguration(array $texts, LlmConfiguration $configuration, ?EmbeddingOptions $options = null) : array**

        Generate embeddings for multiple texts against a specific LLM
        configuration in a single provider call.

        -   *param array $texts:* Array of texts
        -   *param LlmConfiguration $configuration:*

            The
            configuration record to resolve provider/model from

        -   *param ?EmbeddingOptions $options:* Optional config

        *Returns:* array\<array\<float>> Array of vectors

    -   **cosineSimilarity(array $a, array $b) : float**

        Calculate cosine similarity between two vectors.

        -   *param array $a:* First vector
        -   *param array $b:* Second vector

        *Returns:* float Similarity score (-1 to 1)

    -   **findMostSimilar(array $queryVector, array $candidates, int $topK = 5) : array**

        Find most similar vectors from candidates.

        -   *param array $queryVector:* The query vector
        -   *param array $candidates:* Array of candidate vectors
        -   *param int $topK:* Number of results to return

        *Returns:* array Sorted by similarity (highest first)

    -   **pairwiseSimilarities(array $vectors) : array**

        Calculate pairwise similarities between all vectors.

        Returns a 2D matrix where each cell `[i][j]`
        contains the cosine similarity between vectors
        `i` and `j`. Diagonal values are always 1.0.

        -   *param array $vectors:* Array of embedding vectors

        *Returns:* array 2D array of similarity scores

    -   **normalize(array $vector) : array**

        Normalize a vector to unit length.

        -   *param array $vector:* The vector to normalize

        *Returns:* array Normalized vector
