Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationString EvaluatorsComparison EvaluatorsPairwise string comparisonPairwise embedding distanceCustom pairwise evaluatorTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationComparison EvaluatorsPairwise embedding distanceOn this pagePairwise embedding distanceOne way to measure the similarity (or dissimilarity) between two predictions on a shared or similar input is to embed the predictions and compute a vector distance between the two embeddings.[1]You can load the pairwise_embedding_distance evaluator to do this.Note: This returns a distance score, meaning that the lower the number, the more similar the outputs are, according to their embedded representation.Check out the reference docs for the PairwiseEmbeddingDistanceEvalChain for more info.from langchain.evaluation import load_evaluatorevaluator = load_evaluator("pairwise_embedding_distance")evaluator.evaluate_string_pairs(    prediction="Seattle is hot in June", prediction_b="Seattle is cool in June.")    {'score': 0.0966466944859925}evaluator.evaluate_string_pairs(    prediction="Seattle is warm in June", prediction_b="Seattle is cool in June.")    {'score': 0.03761174337464557}Select the Distance Metric‚ÄãBy default, the evaluator uses cosine distance. You can choose a different distance metric if you'd like. from langchain.evaluation import EmbeddingDistancelist(EmbeddingDistance)    [<EmbeddingDistance.COSINE: 'cosine'>,     <EmbeddingDistance.EUCLIDEAN: 'euclidean'>,     <EmbeddingDistance.MANHATTAN: 'manhattan'>,     <EmbeddingDistance.CHEBYSHEV:
Open In Colab
Open In Colab ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationString EvaluatorsComparison EvaluatorsPairwise string comparisonPairwise embedding distanceCustom pairwise evaluatorTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationComparison EvaluatorsPairwise embedding distanceOn this pagePairwise embedding distanceOne way to measure the similarity (or dissimilarity) between two predictions on a shared or similar input is to embed the predictions and compute a vector distance between the two embeddings.[1]You can load the pairwise_embedding_distance evaluator to do this.Note: This returns a distance score, meaning that the lower the number, the more similar the outputs are, according to their embedded representation.Check out the reference docs for the PairwiseEmbeddingDistanceEvalChain for more info.from langchain.evaluation import load_evaluatorevaluator = load_evaluator("pairwise_embedding_distance")evaluator.evaluate_string_pairs(    prediction="Seattle is hot in June", prediction_b="Seattle is cool in June.")    {'score': 0.0966466944859925}evaluator.evaluate_string_pairs(    prediction="Seattle is warm in June", prediction_b="Seattle is cool in June.")    {'score': 0.03761174337464557}Select the Distance Metric‚ÄãBy default, the evaluator uses cosine distance. You can choose a different distance metric if you'd like. from langchain.evaluation import EmbeddingDistancelist(EmbeddingDistance)    [<EmbeddingDistance.COSINE: 'cosine'>,     <EmbeddingDistance.EUCLIDEAN: 'euclidean'>,     <EmbeddingDistance.MANHATTAN: 'manhattan'>,     <EmbeddingDistance.CHEBYSHEV: