diff --git a/js/package.json b/js/package.json index c3ff5e32d..b14aab1f1 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "langsmith", - "version": "0.1.50", + "version": "0.1.51", "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.", "packageManager": "yarn@1.22.19", "files": [ @@ -276,4 +276,4 @@ }, "./package.json": "./package.json" } -} \ No newline at end of file +} diff --git a/js/src/client.ts b/js/src/client.ts index 4d7538bda..49e182fc9 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -2226,6 +2226,13 @@ export class Client { * similar examples in order of most similar to least similar. If no similar * examples are found, random examples will be returned. * + * @param filter A filter string to apply to the search. Only examples will be returned that + * match the filter string. Some examples of filters + * + * - eq(metadata.mykey, "value") + * - and(neq(metadata.my.nested.key, "value"), neq(metadata.mykey, "value")) + * - or(eq(metadata.mykey, "value"), eq(metadata.mykey, "othervalue")) + * * @returns A list of similar examples. * * @@ -2238,13 +2245,22 @@ export class Client { public async similarExamples( inputs: KVMap, datasetId: string, - limit: number + limit: number, + { + filter, + }: { + filter?: string; + } = {} ): Promise { - const data = { + const data: KVMap = { limit: limit, inputs: inputs, }; + if (filter !== undefined) { + data["filter"] = filter; + } + assertUuid(datasetId); const response = await this.caller.call( fetch, diff --git a/js/src/index.ts b/js/src/index.ts index bccaa0015..d55ae6a07 100644 --- a/js/src/index.ts +++ b/js/src/index.ts @@ -12,4 +12,4 @@ export type { export { RunTree, type RunTreeConfig } from "./run_trees.js"; // Update using yarn bump-version -export const __version__ = "0.1.50"; +export const __version__ = "0.1.51"; diff --git a/js/src/tests/few_shot.int.test.ts b/js/src/tests/few_shot.int.test.ts index cc43b3829..484e5a391 100644 --- a/js/src/tests/few_shot.int.test.ts +++ b/js/src/tests/few_shot.int.test.ts @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid"; const TESTING_DATASET_NAME = `test_dataset_few_shot_js_${uuidv4()}`; -test("evaluate can evaluate", async () => { +test("few shot search", async () => { const client = new Client(); const schema: KVMap = { @@ -33,6 +33,7 @@ test("evaluate can evaluate", async () => { const res = await client.createExamples({ inputs: [{ name: "foo" }, { name: "bar" }], outputs: [{ output: 2 }, { output: 3 }], + metadata: [{ somekey: "somevalue" }, { somekey: "someothervalue" }], datasetName: TESTING_DATASET_NAME, }); if (res.length !== 2) { @@ -62,4 +63,16 @@ test("evaluate can evaluate", async () => { expect(examples.length).toBe(2); expect(examples[0].inputs).toEqual({ name: "foo" }); expect(examples[1].inputs).toEqual({ name: "bar" }); + + const filtered_examples = await client.similarExamples( + { name: "foo" }, + dataset.id, + 1, + { + filter: "eq(metadata.somekey, 'somevalue')", + } + ); + + expect(filtered_examples.length).toBe(1); + expect(filtered_examples[0].inputs).toEqual({ name: "foo" }); });