clients/new-js/packages/ai-embeddings/huggingface-server/README.md
This package provides a Hugging Face Inference Server embedding provider for Chroma.
npm install @chroma-core/huggingface-server
import { ChromaClient } from 'chromadb';
import { HuggingfaceServerEmbeddingFunction } from '@chroma-core/huggingface-server';
// Initialize the embedder
const embedder = new HuggingfaceServerEmbeddingFunction({
url: 'https://your-inference-server.com/embed', // Your inference server endpoint
apiKey: 'your-api-key', // Optional, for authenticated servers
// Or use environment variable
apiKeyEnvVar: 'HF_API_KEY',
});
// 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,
});
For authenticated servers, set your API key as an environment variable:
export HF_API_KEY=your-api-key
HF_API_KEY)This embedding function is ideal for:
Your Hugging Face inference server should:
For more information on setting up a Hugging Face Inference Server, see the Hugging Face documentation.