Model

Embedding

Why Embedding Is Needed

LLMs are good at understanding semantics, but databases and search systems can't handle "semantics" — they only do exact matching.

When you ask "find documents related to 'annual company report'," the traditional approach searches for keywords "company," "annual," "report." But if the document says "annual report" instead of "annual company report," or uses "annual financial report," keyword search fails — because it only matches exact text.

Embedding solves this: making computers able to compare "whether meanings are close," not just "whether text is identical."


What Is Embedding

One-line definition: The essence of Embedding is converting text into a sequence of numbers (vectors), so that semantically similar content has close distances in the numeric space.

Think of it as giving each text passage a "fingerprint":

  • Semantically close sentences have similar fingerprints
  • Semantically different sentences have very different fingerprints

For example, these three sentences:

  • "The cat is sleeping"
  • "The kitten is taking a nap"
  • "The rocket launched successfully"

The first two are close in meaning, so their Embeddings have close vector distances; the third is completely different, so its vector is far away.

This "closeness" is typically measured using Cosine Similarity — it calculates how close the vector "direction" is, not the magnitude.


How to Do It: When to Use Embedding

Scenarios suited for Embedding:

  • Semantic search: finding content by meaning, not keywords
  • RAG knowledge bases: providing retrieval foundation for Q&A systems — this is also one of the core steps in RAG
  • Recommendation systems: finding semantically close items or content
  • Text clustering: automatically grouping large amounts of content by topic

Scenarios not suited for Embedding:

  • Exact matching: searching names, IDs, order numbers — keyword search is still needed here
  • Tasks without semantic understanding needs: purely structured queries

Common pitfalls:

  • Embedding models have domain differences: generic models may not be optimal in specialized domains like law, healthcare, finance. For Embedding model selection, see the Embedding Model entry
  • Chunk splitting directly affects results: too small loses context, too large introduces noise
  • Vectors being close doesn't mean the answer is correct: retrieved similar content still needs subsequent judgment

Remember this: Embedding turns "semantics" into "numbers," enabling computers to compare "whether meanings are close."

Related terms: Cosine Similarity · RAG