Journalism AI - v3.0.7
    Preparing search index...

    Function getEmbeddingIdentity

    • Returns the canonical, non-secret identity for an embedding request. Downstream persisted data can compare this value to decide whether vectors are compatible with the current request.

      Parameters

      • options:
            | {
                apiKey?: string;
                beforeRequest?: () => void | Promise<void>;
                cache?: boolean;
                contextWindow?: undefined;
                location?: undefined;
                model?: string;
                ollama?: undefined;
                project?: undefined;
                provider: "gemini";
                verbose?: boolean;
                vertex?: false;
            }
            | {
                apiKey?: string;
                beforeRequest?: () => void | Promise<void>;
                cache?: boolean;
                contextWindow?: undefined;
                location?: string;
                model?: string;
                ollama?: undefined;
                project?: string;
                provider: "gemini";
                verbose?: boolean;
                vertex: true;
            }
            | {
                apiKey?: undefined;
                beforeRequest?: () => void | Promise<void>;
                cache?: boolean;
                contextWindow?: number;
                location?: undefined;
                model?: string;
                ollama?: {
                    embeddingEndpoint?: string;
                    embed(
                        request: {
                            input: string;
                            model: string;
                            options?: { num_ctx?: number };
                        },
                    ): Promise<{ embeddings: number[][] }>;
                };
                project?: undefined;
                provider: "ollama";
                verbose?: boolean;
                vertex?: undefined;
            }
            | {
                apiKey?: undefined;
                beforeRequest?: () => void | Promise<void>;
                cache?: boolean;
                contextWindow?: undefined;
                location?: undefined;
                model?: string;
                ollama?: undefined;
                project?: undefined;
                provider?: undefined;
                verbose?: boolean;
                vertex?: undefined;
            } = {}

        Provider-aware embedding options.

        • {
              apiKey?: string;
              beforeRequest?: () => void | Promise<void>;
              cache?: boolean;
              contextWindow?: undefined;
              location?: undefined;
              model?: string;
              ollama?: undefined;
              project?: undefined;
              provider: "gemini";
              verbose?: boolean;
              vertex?: false;
          }
          • OptionalapiKey?: string

            Gemini API key. Defaults to AI_KEY.

          • OptionalbeforeRequest?: () => void | Promise<void>

            Awaits caller-controlled pacing immediately before an uncached provider request. Cache hits skip this hook. Throwing prevents dispatch and caching. The hook is excluded from embedding identity and cache keys.

            const options = {
            beforeRequest: async () => {
            await new Promise((resolve) => setTimeout(resolve, 100));
            },
            };
          • Optionalcache?: boolean

            Whether to persist and reuse the embedding response. Defaults to true.

          • OptionalcontextWindow?: undefined

            Ollama context windows are not valid for the Gemini API.

          • Optionallocation?: undefined

            Vertex locations are not valid for the Gemini API.

          • Optionalmodel?: string

            The embedding model. Defaults to AI_EMBEDDINGS_MODEL.

          • Optionalollama?: undefined

            Ollama clients are not valid for the Gemini API.

          • Optionalproject?: undefined

            Vertex projects are not valid for the Gemini API.

          • provider: "gemini"

            Explicitly selects the Google embedding provider.

          • Optionalverbose?: boolean

            Whether to log request and timing information.

          • Optionalvertex?: false

            Keeps the request on the Gemini API rather than Vertex AI.

        • {
              apiKey?: string;
              beforeRequest?: () => void | Promise<void>;
              cache?: boolean;
              contextWindow?: undefined;
              location?: string;
              model?: string;
              ollama?: undefined;
              project?: string;
              provider: "gemini";
              verbose?: boolean;
              vertex: true;
          }
          • OptionalapiKey?: string

            Vertex Express Mode API key.

          • OptionalbeforeRequest?: () => void | Promise<void>

            Awaits caller-controlled pacing immediately before an uncached provider request. Cache hits skip this hook. Throwing prevents dispatch and caching. The hook is excluded from embedding identity and cache keys.

            const options = {
            beforeRequest: async () => {
            await new Promise((resolve) => setTimeout(resolve, 100));
            },
            };
          • Optionalcache?: boolean

            Whether to persist and reuse the embedding response. Defaults to true.

          • OptionalcontextWindow?: undefined

            Ollama context windows are not valid for Vertex AI.

          • Optionallocation?: string

            Google Cloud location. Defaults to AI_LOCATION.

          • Optionalmodel?: string

            The embedding model. Defaults to AI_EMBEDDINGS_MODEL.

          • Optionalollama?: undefined

            Ollama clients are not valid for Vertex AI.

          • Optionalproject?: string

            Google Cloud project. Defaults to AI_PROJECT.

          • provider: "gemini"

            Explicitly selects the Google embedding provider.

          • Optionalverbose?: boolean

            Whether to log request and timing information.

          • vertex: true

            Selects the Vertex AI backend.

        • {
              apiKey?: undefined;
              beforeRequest?: () => void | Promise<void>;
              cache?: boolean;
              contextWindow?: number;
              location?: undefined;
              model?: string;
              ollama?: {
                  embeddingEndpoint?: string;
                  embed(
                      request: {
                          input: string;
                          model: string;
                          options?: { num_ctx?: number };
                      },
                  ): Promise<{ embeddings: number[][] }>;
              };
              project?: undefined;
              provider: "ollama";
              verbose?: boolean;
              vertex?: undefined;
          }
          • OptionalapiKey?: undefined

            Gemini and Vertex API keys are not valid for Ollama.

          • OptionalbeforeRequest?: () => void | Promise<void>

            Awaits caller-controlled pacing immediately before an uncached provider request. Cache hits skip this hook. Throwing prevents dispatch and caching. The hook is excluded from embedding identity and cache keys.

            const options = {
            beforeRequest: async () => {
            await new Promise((resolve) => setTimeout(resolve, 100));
            },
            };
          • Optionalcache?: boolean

            Whether to persist and reuse the embedding response. Defaults to true.

          • OptionalcontextWindow?: number

            The model context-window size sent to Ollama.

          • Optionallocation?: undefined

            Vertex locations are not valid for Ollama.

          • Optionalmodel?: string

            The embedding model. Defaults to AI_EMBEDDINGS_MODEL.

          • Optionalollama?: {
                embeddingEndpoint?: string;
                embed(
                    request: {
                        input: string;
                        model: string;
                        options?: { num_ctx?: number };
                    },
                ): Promise<{ embeddings: number[][] }>;
            }

            A custom Ollama client.

            • OptionalembeddingEndpoint?: string

              Non-secret deployment endpoint for custom adapters that are not instances of the Ollama SDK client.

            • embed: function
              • Sends an embedding request to Ollama.

                Parameters

                • request: { input: string; model: string; options?: { num_ctx?: number } }

                Returns Promise<{ embeddings: number[][] }>

          • Optionalproject?: undefined

            Vertex projects are not valid for Ollama.

          • provider: "ollama"

            Explicitly selects Ollama.

          • Optionalverbose?: boolean

            Whether to log request and timing information.

          • Optionalvertex?: undefined

            Vertex selection is not valid for Ollama.

        • {
              apiKey?: undefined;
              beforeRequest?: () => void | Promise<void>;
              cache?: boolean;
              contextWindow?: undefined;
              location?: undefined;
              model?: string;
              ollama?: undefined;
              project?: undefined;
              provider?: undefined;
              verbose?: boolean;
              vertex?: undefined;
          }
          • OptionalapiKey?: undefined

            Direct credentials require an explicit provider.

          • OptionalbeforeRequest?: () => void | Promise<void>

            Awaits caller-controlled pacing immediately before an uncached provider request. Cache hits skip this hook. Throwing prevents dispatch and caching. The hook is excluded from embedding identity and cache keys.

            const options = {
            beforeRequest: async () => {
            await new Promise((resolve) => setTimeout(resolve, 100));
            },
            };
          • Optionalcache?: boolean

            Whether to persist and reuse the embedding response. Defaults to true.

          • OptionalcontextWindow?: undefined

            Provider-specific semantic options require an explicit provider.

          • Optionallocation?: undefined

            Direct deployment selection requires an explicit provider.

          • Optionalmodel?: string

            The embedding model. Defaults to AI_EMBEDDINGS_MODEL.

          • Optionalollama?: undefined

            Custom clients require an explicit provider.

          • Optionalproject?: undefined

            Direct deployment selection requires an explicit provider.

          • Optionalprovider?: undefined

            Omit the discriminator to select the provider from the environment.

          • Optionalverbose?: boolean

            Whether to log request and timing information.

          • Optionalvertex?: undefined

            Direct backend selection requires an explicit provider.

      • environment: { [key: string]: string | undefined } = process.env

        Environment used to resolve omitted values.

      Returns
          | {
              backend: "gemini-api";
              model: string;
              provider: "gemini";
              schemaVersion: 2;
          }
          | {
              backend: "vertex";
              location?: string;
              model: string;
              project?: string;
              provider: "gemini";
              schemaVersion: 2;
          }
          | {
              backend: "ollama";
              contextWindow?: number;
              endpoint: string;
              model: string;
              provider: "ollama";
              schemaVersion: 2;
          }

      The canonical identity used by embedding caches.

      • { backend: "gemini-api"; model: string; provider: "gemini"; schemaVersion: 2 }
        • backend: "gemini-api"

          Resolved Gemini API backend.

        • model: string

          Resolved embedding model.

        • provider: "gemini"

          Resolved provider.

        • schemaVersion: 2

          Cache-compatibility schema for the canonical identity.

      • {
            backend: "vertex";
            location?: string;
            model: string;
            project?: string;
            provider: "gemini";
            schemaVersion: 2;
        }
        • backend: "vertex"

          Resolved Vertex AI backend.

        • Optionallocation?: string

          Resolved Google Cloud location, when configured.

        • model: string

          Resolved embedding model.

        • Optionalproject?: string

          Resolved Google Cloud project, when configured.

        • provider: "gemini"

          Resolved provider.

        • schemaVersion: 2

          Cache-compatibility schema for the canonical identity.

      • {
            backend: "ollama";
            contextWindow?: number;
            endpoint: string;
            model: string;
            provider: "ollama";
            schemaVersion: 2;
        }
        • backend: "ollama"

          Resolved Ollama backend.

        • OptionalcontextWindow?: number

          Context-window size when explicitly configured.

        • endpoint: string

          Non-secret Ollama endpoint identity.

        • model: string

          Resolved embedding model.

        • provider: "ollama"

          Resolved provider.

        • schemaVersion: 2

          Cache-compatibility schema for the canonical identity.

      const identity = getEmbeddingIdentity({
      provider: "ollama",
      model: "nomic-embed-text",
      contextWindow: 8192,
      });