Skip to content

improve bm25 sorting function #8427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AllenFang
Copy link
Contributor

Goal:

  • make good use of the sorter method signature of BM25
  • refactor the BM25 method to solve the problem if sorter param assign, it's very difficult to map the result to original data.
    • Clearly define the input and output type of BM25 method
  • now the sorter can not only sort by score but also anything in the docs

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 27, 2025
Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jun 27, 2025 9:26am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jun 27, 2025 9:26am

@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Jun 27, 2025
@AllenFang AllenFang force-pushed the chore/use-default-bm25-sorter branch from 6af9ed3 to 559f7c0 Compare June 27, 2025 09:02
@AllenFang AllenFang force-pushed the chore/use-default-bm25-sorter branch from 559f7c0 to 2521fdd Compare June 27, 2025 09:03
).length;
return Math.log(
(documents.length - relevantDocuments + 0.5) / (relevantDocuments + 0.5) + 1
);
};

export interface BMInputDocument<T> {
/** The text from the original document */
text: string;
Copy link
Contributor Author

@AllenFang AllenFang Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if team prefer to use a method to extract the text rather than adding another text field BMInputDocument:

ex:

export interface BMInputDocument<T> {
  extractText: (docs: T) => string;
  /** The original document */
  docs: T;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant