Skip to content

BM25 is not a function #2210

@tpiros

Description

@tpiros

Describe the bug
The following sample code (taken from this repo's tests) throws a TypeError: BM25 is not a function.

To Reproduce
Code to reproduce the behavior:

import { Bm25Retriever } from "@llamaindex/bm25-retriever";
import { OpenAIEmbedding } from "@llamaindex/openai";
import { PDFReader } from "@llamaindex/readers/pdf";
import { MetadataMode, Settings, VectorStoreIndex } from "llamaindex";

Settings.embedModel = new OpenAIEmbedding();

async function main() {
  // Load PDF
  const reader = new PDFReader();
  const documents = await reader.loadData("./data/brk-2022.pdf");

  // Split text and create embeddings. Store them in a VectorStoreIndex
  const index = await VectorStoreIndex.fromDocuments(documents);

  const retriever = new Bm25Retriever({
    docStore: index.docStore,
    topK: 3,
  });

  // Query the data
  const response = await retriever.retrieve({
    query: "What mistakes did Warren E. Buffett make?",
  });

  // Output response
  response.forEach((r) => {
    console.log(`Score: ${r.score}`);
    console.log(`Text: ${r.node.getContent(MetadataMode.NONE)}`);
  });
}

main().catch(console.error);

Expected behavior
BM25 should run :)

I was able to pinpoint the issue. In dist/index.js the import from okapibm25 seems to require the call to be done as const scores = BM25.default(contents, queryStr.toLowerCase().split(/\s+/)); instead of the present const scores = BM25(contents, queryStr.toLowerCase().split(/\s+/));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions