Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationString EvaluatorsCriteria EvaluationCustom String EvaluatorEmbedding DistanceExact MatchRegex MatchScoring EvaluatorString DistanceComparison EvaluatorsTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationString EvaluatorsEmbedding DistanceOn this pageEmbedding DistanceTo measure semantic similarity (or dissimilarity) between a prediction and a reference label string, you could use a vector vector distance metric the two embedded representations using the embedding_distance evaluator.[1]Note: This returns a distance score, meaning that the lower the number, the more similar the prediction is to the reference, according to their embedded representation.Check out the reference docs for the EmbeddingDistanceEvalChain for more info.from langchain.evaluation import load_evaluatorevaluator = load_evaluator("embedding_distance")evaluator.evaluate_strings(prediction="I shall go", reference="I shan't go")    {'score': 0.0966466944859925}evaluator.evaluate_strings(prediction="I shall go", reference="I will go")    {'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: 'chebyshev'>,     <EmbeddingDistance.HAMMING: 'hamming'>]# You can load by enum or by raw python
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 EvaluatorsCriteria EvaluationCustom String EvaluatorEmbedding DistanceExact MatchRegex MatchScoring EvaluatorString DistanceComparison EvaluatorsTrajectory EvaluatorsExamplesFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyMoreGuidesEvaluationString EvaluatorsEmbedding DistanceOn this pageEmbedding DistanceTo measure semantic similarity (or dissimilarity) between a prediction and a reference label string, you could use a vector vector distance metric the two embedded representations using the embedding_distance evaluator.[1]Note: This returns a distance score, meaning that the lower the number, the more similar the prediction is to the reference, according to their embedded representation.Check out the reference docs for the EmbeddingDistanceEvalChain for more info.from langchain.evaluation import load_evaluatorevaluator = load_evaluator("embedding_distance")evaluator.evaluate_strings(prediction="I shall go", reference="I shan't go")    {'score': 0.0966466944859925}evaluator.evaluate_strings(prediction="I shall go", reference="I will go")    {'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: 'chebyshev'>,     <EmbeddingDistance.HAMMING: 'hamming'>]# You can load by enum or by raw python