Created
August 29, 2025 03:02
-
-
Save thangman22/5d331ca01deaee96b5f2c4781c079b60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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