Skip to content

Commit

Permalink
feat(tools): add minScore filter condition for SimilarityTool
Browse files Browse the repository at this point in the history
Ref: #144
Signed-off-by: Tomas Dvorak <[email protected]>
  • Loading branch information
Tomas2D committed Jan 2, 2025
1 parent fb2153c commit 6598906
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tools/similarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "./base.js";
import { string, z } from "zod";
import { RunContext } from "@/context.js";
import { map, pipe, prop, sortBy, take } from "remeda";
import { filter, map, pipe, prop, sortBy, take } from "remeda";
import { Emitter } from "@/emitter/emitter.js";

const documentSchema = z.object({ text: string() }).passthrough();
Expand All @@ -50,6 +50,7 @@ export interface SimilarityToolOptions<TProviderOptions = unknown> extends BaseT
export interface SimilarityToolRunOptions<TProviderOptions = unknown> extends BaseToolRunOptions {
provider?: TProviderOptions;
maxResults?: number;
minScore?: number;
}

export interface SimilarityToolResult {
Expand Down Expand Up @@ -99,6 +100,7 @@ export class SimilarityTool<TProviderOptions> extends Tool<
documentIndex: idx,
score,
})),
filter(({ score }) => score >= (options.minScore ?? 0)),
sortBy([prop("score"), "desc"]),
take(options?.maxResults ?? this.options.maxResults ?? Infinity),
(data) =>
Expand Down

0 comments on commit 6598906

Please sign in to comment.