Ollama Chroma 嵌入函数
这个软件包为Chroma提供Ollama嵌入提供商,允许您使用本地主机Ollama模型.
安装
npm install @chroma-core/ollama
使用量
import { ChromaClient } from 'chromadb';
import { OllamaEmbeddingFunction } from '@chroma-core/ollama';
// Initialize the embedder
const embedder = new OllamaEmbeddingFunction({
url: 'http://localhost:11434', // Default Ollama server URL
model: 'chroma/all-minilm-l6-v2-f32', // Default model
});
// 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,
});
先决条件
- 安装 Ollama 从 欧拉玛.ai
- 启动 Ollama 服务器 :
ollama serve - 绘制嵌入模型 :
ollama pull chroma/all-minilm-l6-v2-f32
配置选项
- url 密码: Ollama 服务器 URL( 默认 ):
http://localhost:11434(中文(简体) ) - 模式: 嵌入所用的模型名称( 默认值 :
chroma/all-minilm-l6-v2-f32(中文(简体) )
支持的模式
通过 Ollama 提供的流行嵌入模型 :
chroma/all-minilm-l6-v2-f32(默认,384个维)nomic-embed-text(768个维)mxbai-embed-large(1024个维)snowflake-arctic-embed
使用 :
ollama pull <model-name>
浏览器支持
这个软件包同时在Node.js和浏览器的环境下工作,自动检测运行时间并使用适当的Ollama客户端.