Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãOPromptsPrompt templatesExample selectorsCustom example selectorSelect by lengthSelect by maximal marginal relevance (MMR)Select by n-gram overlapSelect by similarityLanguage modelsOutput parsersRetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesModel I/‚ÄãOPromptsExample selectorsSelect by n-gram overlapSelect by n-gram overlapThe NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. The selector allows for a threshold score to be set. Examples with an ngram overlap score less than or equal to the threshold are excluded. The threshold is set to -1.0, by default, so will not exclude any examples, only reorder them. Setting the threshold to 0.0 will exclude examples that have no ngram overlaps with the input.from langchain.prompts import PromptTemplate, FewShotPromptTemplatefrom langchain.prompts.example_selector.ngram_overlap import NGramOverlapExampleSelectorexample_prompt = PromptTemplate(    input_variables=["input", "output"],    template="Input: {input}\nOutput: {output}",)# Examples of a fictional translation task.examples = [    {"input": "See Spot run.", "output": "Ver correr a Spot."},    {"input": "My dog barks.", "output": "Mi perro ladra."},    {"input": "Spot can run.", "output": "Spot puede correr."},]example_selector = NGramOverlapExampleSelector(    # The examples it has available to choose from.    examples=examples,    # The PromptTemplate being used to format the examples.    example_prompt=example_prompt,    # The threshold, at which selector stops.    # It is set to -1.0 by default.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive.
The NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãOPromptsPrompt templatesExample selectorsCustom example selectorSelect by lengthSelect by maximal marginal relevance (MMR)Select by n-gram overlapSelect by similarityLanguage modelsOutput parsersRetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreModulesModel I/‚ÄãOPromptsExample selectorsSelect by n-gram overlapSelect by n-gram overlapThe NGramOverlapExampleSelector selects and orders examples based on which examples are most similar to the input, according to an ngram overlap score. The ngram overlap score is a float between 0.0 and 1.0, inclusive. The selector allows for a threshold score to be set. Examples with an ngram overlap score less than or equal to the threshold are excluded. The threshold is set to -1.0, by default, so will not exclude any examples, only reorder them. Setting the threshold to 0.0 will exclude examples that have no ngram overlaps with the input.from langchain.prompts import PromptTemplate, FewShotPromptTemplatefrom langchain.prompts.example_selector.ngram_overlap import NGramOverlapExampleSelectorexample_prompt = PromptTemplate(    input_variables=["input", "output"],    template="Input: {input}\nOutput: {output}",)# Examples of a fictional translation task.examples = [    {"input": "See Spot run.", "output": "Ver correr a Spot."},    {"input": "My dog barks.", "output": "Mi perro ladra."},    {"input": "Spot can run.", "output": "Spot puede correr."},]example_selector = NGramOverlapExampleSelector(    # The examples it has available to choose from.    examples=examples,    # The PromptTemplate being used to format the examples.    example_prompt=example_prompt,    # The threshold, at which selector stops.    # It is set to -1.0 by default.