GEMINI_EMBEDDING_MODEL (services/geminiEmbeddings.ts)

AI-RAG-Assistant-Chatbot · server/src/services/geminiEmbeddings.ts · typescript · MIT
ai, tag:embed-classified

TypeScript module for Gemini embeddings with retry logic.

// Source: https://github.com/hoangsonww/AI-RAG-Assistant-Chatbot | License: MIT | Copyright 2026 Son Nguyen
// Provided via justclaw.it.com; keep this notice with the code.
import {
  GoogleGenerativeAI,
  TaskType,
  type EmbedContentRequest,
  type GenerativeModel,
} from "@google/generative-ai";

export const GEMINI_EMBEDDING_MODEL = "models/gemini-embedding-001";
export const GEMINI_EMBEDDING_DIMENSION = 768;

interface GeminiEmbedContentRequest extends EmbedContentRequest {
  outputDimensionality: number;
}

const buildEmbeddingRequest = (
  text: string,
  taskType?: TaskType,
): GeminiEmbedContentRequest => ({
  content: {
    role: "user",
    parts: [{ text }],
  },
  taskType,
  outputDimensionality: GEMINI_EMBEDDING_DIMENSION,
});

export const getEmbeddingModel = (apiKey: stri

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key