import { BM25Retriever } from "@langchain/community/retrievers/bm25";
const retriever = BM25Retriever.fromDocuments([
{ pageContent: "Buildings are made out of brick", metadata: {} },
{ pageContent: "Buildings are made out of wood", metadata: {} },
{ pageContent: "Buildings are made out of stone", metadata: {} },
{ pageContent: "Cars are made out of metal", metadata: {} },
{ pageContent: "Cars are made out of plastic", metadata: {} },
{ pageContent: "mitochondria is the powerhouse of the cell", metadata: {} },
{ pageContent: "mitochondria is made of lipids", metadata: {} },
], { k: 4 });
// Will return the 4 documents reranked by the BM25 algorithm
await retriever.invoke("mitochondria");