@langchain/community
Version:
Third-party integrations for LangChain.js
31 lines (30 loc) • 958 B
JavaScript
import { test, expect } from "@jest/globals";
import { HuggingFaceInferenceEmbeddings } from "../hf.js";
import { HNSWLib } from "../../vectorstores/hnswlib.js";
test("HuggingFaceInferenceEmbeddings", async () => {
const embeddings = new HuggingFaceInferenceEmbeddings();
const texts = [
"Hello world!",
"Hello bad world!",
"Hello nice world!",
"Hello good world!",
"1 + 1 = 2",
"1 + 1 = 3",
];
const queryEmbedding = await embeddings.embedQuery(texts[0]);
expect(queryEmbedding).toHaveLength(768);
expect(typeof queryEmbedding[0]).toBe("number");
const store = await HNSWLib.fromTexts(texts, {}, embeddings);
expect(await store.similaritySearch(texts[4], 2)).toMatchInlineSnapshot(`
[
Document {
"metadata": {},
"pageContent": "1 + 1 = 2",
},
Document {
"metadata": {},
"pageContent": "1 + 1 = 3",
},
]
`);
});