Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created August 29, 2025 03:02
Show Gist options
  • Select an option

  • Save thangman22/5d331ca01deaee96b5f2c4781c079b60 to your computer and use it in GitHub Desktop.

Select an option

Save thangman22/5d331ca01deaee96b5f2c4781c079b60 to your computer and use it in GitHub Desktop.
import { pipeline, env } from '@huggingface/transformers';
import faqs from "@/faq.json";
const extractor = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
const embeddings = [];
for (const faq of faqs) {
const embedding = await extractor(faq.question + " " + faq.answer, {
pooling: "mean",
normalize: true,
});
const embeddingArray = embedding.tolist()[0];
embeddings.push({
embedding: embeddingArray,
text: faq.question,
metadata: { question: faq.question, answer: faq.answer },
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment