Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
feat(meta-tools): add hybrid BM25 + TF-IDF search strategy#122
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2fa924e041941024c601e8e763477db7f02File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -14,6 +14,7 @@ import type { | ||||||
| ToolParameters, | ||||||
| } from './types'; | ||||||
| import { StackOneError } from './utils/errors'; | ||||||
| import { TfidfIndex } from './utils/tfidf-index'; | ||||||
| /** | ||||||
| * Base class for all tools. Provides common functionality for executing API calls | ||||||
| @@ -378,10 +379,15 @@ export class Tools implements Iterable<BaseTool> { | ||||||
| /** | ||||||
| * Return meta tools for tool discovery and execution | ||||||
| * @beta This feature is in beta and may change in future versions | ||||||
| * @param hybridAlpha - Weight for BM25 in hybrid search (0-1, default 0.2). Lower values favor BM25 scoring. | ||||||
| ||||||
| * @paramhybridAlpha-WeightforBM25inhybridsearch(0-1,default0.2).LowervaluesfavorBM25scoring. | |
| * @paramhybridAlpha-WeightforBM25inhybridsearch(0-1,default0.2).HighervaluesfavorBM25scoring. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { expect, test } from 'bun:test'; | ||
| import { TfidfIndex } from './tfidf-index'; | ||
| test('ranks documents by cosine similarity with tf-idf weighting', () => { | ||
| const index = new TfidfIndex(); | ||
| index.build([ | ||
| { id: 'doc1', text: 'alpha beta' }, | ||
| { id: 'doc2', text: 'alpha alpha' }, | ||
| { id: 'doc3', text: 'beta gamma' }, | ||
| ]); | ||
| const [best, second] = index.search('alpha'); | ||
| expect(best?.id).toBe('doc2'); | ||
| expect(best?.score ?? 0).toBeCloseTo(1, 5); | ||
| expect(second?.id).toBe('doc1'); | ||
| expect(second?.score ?? 0).toBeGreaterThan(0); | ||
| expect(second?.score ?? 0).toBeLessThan(best?.score ?? 0); | ||
| }); | ||
| test('drops stopwords and punctuation when tokenizing', () => { | ||
| const index = new TfidfIndex(); | ||
| index.build([ | ||
| { id: 'doc1', text: 'schedule onboarding meeting' }, | ||
| { id: 'doc2', text: 'escalate production incident' }, | ||
| ]); | ||
| const [result] = index.search('the onboarding meeting!!!'); | ||
| expect(result?.id).toBe('doc1'); | ||
| expect(result?.score ?? 0).toBeGreaterThan(0); | ||
| }); | ||
| test('returns no matches when query shares no terms with the corpus', () => { | ||
| const index = new TfidfIndex(); | ||
| index.build([ | ||
| { id: 'doc1', text: 'generate billing statement' }, | ||
| { id: 'doc2', text: 'update user profile' }, | ||
| ]); | ||
| const results = index.search('predict weather forecast'); | ||
| expect(results).toHaveLength(0); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new comment says the default strategy is BM25, but metaTools() now defaults to the hybrid BM25 + TF-IDF search. Please update the comment to reflect the hybrid default so it doesn’t mislead future readers.
Prompt for AI agents