임베딩 유사도 측정하기
벡터 검색을 뒷받침하는 거리 및 유사도 지표를 이해하고 적절한 지표를 선택하는 방법을 학습해 보세요.
임베딩 유사도 측정하기은(는) CoddyKit의 무료 LangChain / RAG / Vector DBs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 LangChain / RAG / Vector DBs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
From Vectors to Meaning
An embedding maps text to a list of numbers in high-dimensional space. Texts with similar meaning land close together. To rank results we need a way to measure that closeness.
Cosine Similarity
Cosine similarity measures the angle between two vectors, ignoring their length. It ranges from -1 (opposite) to 1 (identical direction).
import numpy as np
def cosine(a, b):
a, b = np.array(a), np.array(b)
return a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(cosine([1, 0], [1, 1])) # ~0.707Euclidean Distance
Euclidean (L2) distance is the straight-line distance between two points. Smaller means more similar. Unlike cosine, it is sensitive to magnitude.
import numpy as np
def l2(a, b):
return np.linalg.norm(np.array(a) - np.array(b))
print(l2([0, 0], [3, 4])) # 5.0Dot Product
The dot product multiplies matching dimensions and sums them. For normalized vectors it equals cosine similarity, which is why many stores normalize first.
import numpy as np
def dot(a, b):
return float(np.array(a).dot(np.array(b)))
print(dot([1, 2, 3], [4, 5, 6])) # 32.0Normalization
Dividing a vector by its length gives a unit vector. After normalization, dot product and cosine similarity become equivalent, simplifying the math.
import numpy as np
def normalize(v):
v = np.array(v, dtype=float)
return v / np.linalg.norm(v)
print(normalize([3, 4])) # [0.6 0.8]Choosing a Metric
Most modern text embedding models are trained for cosine similarity. Use cosine unless your provider documentation recommends otherwise.
- Cosine: direction matters, length ignored
- L2: absolute position matters
- Dot: cosine on normalized data
Similarity vs. Distance
Beware the inversion: higher cosine = more similar, but higher L2 = less similar. Vector stores expose this difference, sometimes returning a score you must interpret.
Why High Dimensions Help
Embeddings often have hundreds or thousands of dimensions. More dimensions give the model room to separate subtle differences in meaning, at the cost of more storage and compute.
Setting Metric in a Store
When creating a collection you declare the metric. Many libraries default to cosine.
import chromadb
client = chromadb.Client()
col = client.create_collection(
name="docs",
metadata={"hnsw:space": "cosine"}
)Ranking Search Results
Search computes the chosen metric between the query embedding and every stored vector, then returns the top-k closest. The metric directly shapes which documents win.
query_vec = embed("refund policy")
scored = [(cosine(query_vec, d.vec), d) for d in docs]
scored.sort(reverse=True)
top3 = scored[:3]Pitfall: Mixing Models
Vectors from different embedding models live in different spaces and are not comparable. Always embed your query with the same model you used to index the documents.
Quick Check
Test your grasp of similarity metrics.
Recap
You explored how similarity is measured:
- Cosine compares direction (most common for text)
- Euclidean compares position
- Dot product equals cosine on normalized vectors
- Always query and index with the same model
자주 묻는 질문
“임베딩 유사도 측정하기” 강의는 무료인가요?
네 — “임베딩 유사도 측정하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 LangChain / RAG / Vector DBs 강의 전체를 잠금 해제할 수 있습니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.
“임베딩 유사도 측정하기”에서 뭘 배우나요?
벡터 검색을 뒷받침하는 거리 및 유사도 지표를 이해하고 적절한 지표를 선택하는 방법을 학습해 보세요. 브라우저에서 직접 실행하는 실습 코드로 LangChain / RAG / Vector DBs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
LangChain / RAG / Vector DBs을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 LangChain / RAG / Vector DBs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“임베딩 유사도 측정하기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 LangChain / RAG / Vector DBs 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 LangChain / RAG / Vector DBs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 텍스트 임베딩 이해
- 벡터 데이터베이스 입문
- 임베딩 저장 및 검색
- 임베딩 유사도 측정하기