Chroma 默认嵌入函数
此软件包为使用Hugging Face Transformers.js的Chroma提供了默认嵌入功能. 它完全运行于内浏览器或节点.js而不需要外部API呼叫.
安装
npm install @chroma-core/default-embed
使用量
import { ChromaClient } from 'chromadb';
import { DefaultEmbeddingFunction } from '@chroma-core/default-embed';
// Initialize with default settings
const embedder = new DefaultEmbeddingFunction();
// Or customize the configuration
const customEmbedder = new DefaultEmbeddingFunction({
modelName: 'Xenova/all-MiniLM-L6-v2', // Default model
revision: 'main',
dtype: 'fp32', // or 'uint8' for quantization
wasm: false, // Set to true to use WASM backend
});
// 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,
});
配置选项
- 模型Name: hugging Face模型名(默认:
Xenova/all-MiniLM-L6-v2(中文(简体) ) - 订正: 模型修订(默认:
main(中文(简体) ) - d 类型: 量化的数据类型(
fp32, (中文(简体) ),fp16, (中文(简体) ),q8, (中文(简体) ),uint8页:1 - 数量: 折旧,使用
dtype换成 - 原声: 为 ONNX 运行时使用 WASM 后端
特征
- 不需要 API 密钥: 无外部依赖的本地运行
- 浏览器兼容性: 在节点和浏览器环境中工作
- 量化支持: 使用各种量化选项来缩小模型大小
- WASM 后端软件: 可选 WASM 支持更好的浏览器性能
默认模式( E)Xenova/all-MiniLM-L6-v2)产生384维嵌入并适合大多数通用语义搜索任务.