Google 双子座嵌入函数
这个软件包利用Google Generative AI SDK为Chroma提供谷歌双子嵌入供应商.
安装
npm install @chroma-core/google-gemini
使用量
import { ChromaClient } from 'chromadb';
import { GoogleGeminiEmbeddingFunction } from '@chroma-core/google-gemini';
// Initialize the embedder
const embedder = new GoogleGeminiEmbeddingFunction({
apiKey: 'your-api-key', // Or set GEMINI_API_KEY env var
modelName: 'text-embedding-004', // Optional, defaults to latest model
taskType: 'RETRIEVAL_DOCUMENT', // Optional
});
// Create a new ChromaClient
const client = new ChromaClient({
path: 'http://localhost:8000',
});
// Create a collection with the embedder
const collection = await client.createCollection({
name: 'my-collection',
embeddingFunction: embedder,
});
// Add documents
await collection.add({
ids: ["1", "2", "3"],
documents: ["Document 1", "Document 2", "Document 3"],
});
// Query documents
const results = await collection.query({
queryTexts: ["Sample query"],
nResults: 2,
});
配置
将您的 Google AI API 密钥设定为环境变量 :
export GEMINI_API_KEY=your-api-key
从中获取您的 API 密钥 谷歌AI工作室。 。 。 .
配置选项
- 键: 您的 Google AI API 密钥( 或通过环境变量设置)
- apiKeyEnvVar 密码API 密钥的环境变量名( 默认 ):
GEMINI_API_KEY(中文(简体) ) - 模型Name: 嵌入所用的模型
- 任务类型: 嵌入请求的任务类型(例如,
RETRIEVAL_DOCUMENT, (中文(简体) ),RETRIEVAL_QUERY(中文(简体) )
支持的模式
text-embedding-004(最新数据)embedding-001
检查 Google AI文档 用于更新现有嵌入模型列表.