1.0.0 • Published 8 months ago

huggingface-embeddings v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Huggingface embeddings

Hugging face Embeddings function for Chroma Db

Installation

npm i huggingface-embeddings

Example Usage

import { ChromaClient } from 'chromadb';
import { HuggingFaceEmbeddingFunction } from 'huggingface-embeddings'

const API_URL = "https://api-inference.huggingface.co/pipeline/feature-extraction/sentence-transformers/all-mpnet-base-v2" //example embedding model
const API_KEY = "my-api-key" // your hugging face api key
const client = new ChromaClient();
const embedder = new HuggingFaceEmbeddingFunction({ api_path: API_URL, api_key: API_KEY })

const collection = await client.createCollection({ name: "test1", embeddingFunction: embedder })

await collection.add({
    ids: ["id1", "id2", "id3"],
    metadatas: [{ "chapter": "3", "verse": "16" }, { "chapter": "3", "verse": "5" }, { "chapter": "29", "verse": "11" }],
    documents: ["lorem ipsum...", "doc2", "doc3"],
})

const results = await collection.query({
    nResults: 2,
    queryTexts: ["doc"]
})
console.log(results);

Contributions

  • If you happen to see missing feature or a bug, feel free to open an issue.
  • Pull requests are welcomed too!

License

MIT

1.0.0

8 months ago

0.0.1

8 months ago