LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangSmith
  • Client
  • Run Trees
  • Traceable
  • Evaluation
  • Schemas
  • Langchain
  • Jest
  • Vitest
  • Wrappers
  • Anonymizer
  • Traceable
  • Jestlike
  • Vercel
  • Anthropic
  • Sandbox
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangSmith
ClientRun TreesTraceableEvaluationSchemasLangchainJestVitestWrappersAnonymizerTraceableJestlikeVercelAnthropicSandbox
Language
Theme
JavaScriptlangsmithclientClientsimilarExamples
Method●Since v0.1

similarExamples

Lets you run a similarity search query on a dataset.

Requires the dataset to be indexed. Please see the indexDataset method to set up indexing.

Copy
similarExamples(
  inputs: KVMap,
  datasetId: string,
  limit: number,
  filter: __type = {}
): Promise<ExampleSearch[]>

Parameters

NameTypeDescription
inputs*KVMap

The input on which to run the similarity search. Must have the same schema as the dataset.

datasetId*string

The dataset to search for similar examples.

limit*number

The maximum number of examples to return. Will return the top limit most similar examples in order of most similar to least similar. If no similar examples are found, random examples will be returned.

filter__type
Default:{}

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"))

Example

Copy
dataset_id = "123e4567-e89b-12d3-a456-426614174000"
inputs = {"text": "How many people live in Berlin?"}
limit = 5
examples = await client.similarExamples(inputs, dataset_id, limit)
View source on GitHub