{question}。
使用方法
相关
官方原文:src/oss/javascript/integrations/retrievers/hyde.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
使用 LangChain JavaScript 与 Hyde 检索器集成。
{question}。
import { OpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { MemoryVectorStore } from "@langchain/classic/vectorstores/memory";
import { HydeRetriever } from "@langchain/classic/retrievers/hyde";
import { Document } from "@langchain/core/documents";
const embeddings = new OpenAIEmbeddings();
const vectorStore = new MemoryVectorStore(embeddings);
const llm = new OpenAI();
const retriever = new HydeRetriever({
vectorStore,
llm,
k: 1,
});
await vectorStore.addDocuments(
[
"My name is John.",
"My name is Bob.",
"My favourite food is pizza.",
"My favourite food is pasta.",
].map((pageContent) => new Document({ pageContent }))
);
const results = await retriever.invoke("What is my favourite food?");
console.log(results);
/*
[
Document { pageContent: 'My favourite food is pasta.', metadata: {} }
]
*/
官方原文:src/oss/javascript/integrations/retrievers/hyde.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。