모든 벡터 임베딩이 정규화되었는지 여부에 따라 유사성을 찾는 데 사용할 유사성 측정을 결정할 수 있습니다. 정규화된 벡터 임베딩의 크기(길이)는 정확히 1.0입니다.
또한 모델이 어떤 거리 함수로 학습되었는지 알고 있다면 해당 거리 함수를 사용하여 벡터 임베딩 간의 유사성을 측정할 수 있습니다.
정규화된 데이터
모든 벡터 임베딩이 정규화된 데이터 세트가 있다면, 세 함수 모두 동일한 시맨틱 검색 결과를 제공합니다. 기본적으로 각 함수는 서로 다른 값을 반환하지만 해당 값은 동일한 방식으로 정렬됩니다. 임베딩이 정규화될 때는 일반적으로 DOT_PRODUCT()가 가장 계산 효율적이지만 대부분의 경우 그 차이는 무시할 수 있을 정도입니다. 하지만 애플리케이션이 성능에 매우 민감한 경우 DOT_PRODUCT()가 성능 조정에 도움이 될 수 있습니다.
비정규화된 데이터
벡터 임베딩이 정규화되지 않은 데이터 세트가 있는 경우 함수로서 내적에서 거리를 측정하지 않기 때문에 DOT_PRODUCT()를 거리 함수로 사용하는 것은 수학적으로 올바르지 않습니다. 임베딩이 생성된 방법과 원하는 검색 유형에 따라 COSINE_DISTANCE() 또는 EUCLIDEAN_DISTANCE() 함수에서 다른 함수보다 주관적으로 더 나은 검색 결과를 생성할 수 있습니다.
사용 사례에 가장 적합한 방식을 결정하려면 COSINE_DISTANCE() 또는 EUCLIDEAN_DISTANCE()를 실험해야 할 수 있습니다.
데이터가 정규화되었는지 또는 비정규화되었는지 확실하지 않음
데이터가 정규화되었는지 여부가 확실하지 않고 DOT_PRODUCT()를 사용하려는 경우 대신 COSINE_DISTANCE()를 사용하는 것이 좋습니다.
COSINE_DISTANCE()는 정규화가 내장된 DOT_PRODUCT()와 같습니다.
COSINE_DISTANCE()를 사용하여 측정한 유사성의 범위는 0~2입니다. 결과가 0에 가까우면 벡터가 매우 유사하다는 것을 나타냅니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-05(UTC)"],[],[],null,["# Choose among vector distance functions to measure vector embeddings similarity\n\n| **Note:** This feature is available with the Spanner Enterprise edition and Enterprise Plus edition. For more information, see the [Spanner editions overview](/spanner/docs/editions-overview).\n\n\u003cbr /\u003e\n\nThis page describes how to choose among the vector distance functions provided\nin Spanner to measure similarity between vector embeddings.\n\nAfter you've [generated embeddings](/spanner/docs/ml-tutorial-embeddings) from\nyour Spanner data, you can perform a similarity search using vector\ndistance functions. The following table describes the vector distance functions\nin Spanner.\n\nChoose a similarity measure\n---------------------------\n\nDepending on whether or not all your vector embeddings are normalized, you can\ndetermine which similarity measure to use to find similarity. A normalized\nvector embedding has a magnitude (length) of exactly 1.0.\n\nIn addition, if you know which distance function your model was trained with,\nuse that distance function to measure similarity between your vector\nembeddings.\n\n**Normalized data**\n\nIf you have a dataset where all vector embeddings are normalized, then all three\nfunctions provide the same semantic search results. In essence, although each\nfunction returns a different value, those values sort the same way. When\nembeddings are normalized, `DOT_PRODUCT()` is usually the most computationally\nefficient, but the difference is negligible in most cases. However, if your\napplication is highly performance sensitive, `DOT_PRODUCT()` might help with\nperformance tuning.\n\n**Non-normalized data**\n\nIf you have a dataset where vector embeddings aren't normalized,\nthen it's not mathematically correct to use `DOT_PRODUCT()` as a distance\nfunction because dot product as a function doesn't measure distance. Depending\non how the embeddings were generated and what type of search is preferred,\neither the `COSINE_DISTANCE()` or `EUCLIDEAN_DISTANCE()` function produces\nsearch results that are subjectively better than the other function.\nExperimentation with either `COSINE_DISTANCE()` or `EUCLIDEAN_DISTANCE()` might\nbe necessary to determine which is best for your use case.\n\n**Unsure if data is normalized or non-normalized**\n\nIf you're unsure whether or not your data is normalized and you want to use\n`DOT_PRODUCT()`, we recommend that you use `COSINE_DISTANCE()` instead.\n`COSINE_DISTANCE()` is like `DOT_PRODUCT()` with normalization built-in.\nSimilarity measured using `COSINE_DISTANCE()` ranges from `0` to `2`. A result\nthat is close to `0` indicates the vectors are very similar.\n\nWhat's next\n-----------\n\n- Learn more about how to [perform a vector search by finding the k-nearest neighbor](/spanner/docs/find-k-nearest-neighbors).\n- Learn how to [export embeddings to Vertex AI Vector Search](/spanner/docs/vector-search-embeddings).\n- Learn more about the [GoogleSQL `COSINE_DISTANCE()`, `EUCLIDEAN_DISTANCE()`, and `DOT_PRODUCT()`](/spanner/docs/reference/standard-sql/mathematical_functions) functions.\n- Learn more about the [PostgreSQL `spanner.cosine_distance()`, `spanner.euclidean_distance(), and spanner.dot_product()`](/spanner/docs/reference/postgresql/functions-and-operators#mathematical) functions."]]