AI Compass

Embeddings and semantic search

Turning text into numbers that capture meaning, so you can search by idea rather than exact words.

What is it?

An embedding is a list of numbers that represents the meaning of a piece of text, an image or other data. Texts with similar meanings get similar numbers, even if they use different words: "How do I reset my password?" ends up close to "I forgot my login".

Semantic search uses embeddings to find items by meaning. You turn your documents into embeddings once and store them, often in a vector database. When someone searches, their query is turned into an embedding too, and the closest matches are returned. This is a core building block of RAG, recommendations and duplicate detection.

Which models use it?

  • OpenAI, Google and Cohere offer embedding models through their APIs.
  • Open-source embedding models are available on Hugging Face.
  • Vector databases such as Pinecone, Weaviate, Qdrant and the pgvector extension for PostgreSQL store embeddings.
  • Search and recommendation features in many apps use embeddings behind the scenes.

How to use it

  1. Pick an embedding model that supports your languages and content type.
  2. Split long documents into passages before embedding them.
  3. Store each embedding with its original text and a reference to the source.
  4. Embed the user's query with the same model.
  5. Return the closest matches and, if useful, re-rank or filter them.
  6. Check search quality with real queries and adjust chunk size or model if needed.

Benefits

  • Finds relevant results even when the words don't match.
  • Works across phrasing and, with suitable models, across languages.
  • Fast to search once the embeddings are stored.
  • Useful for search, recommendations, clustering and finding duplicates.

Limits and risks

  • Embeddings from different models are not compatible with each other.
  • Exact terms such as product codes or names can be missed; keyword search may still be needed.
  • Re-embedding everything is required when you change models.
  • Embeddings of personal data are still personal data and need protection.

Prompt template

Copy it, replace the parts in [brackets] and paste it into any AI chat.

I want to build semantic search over [type of content, e.g. support articles] in [languages]. Explain the pipeline in plain steps: chunking, embedding, storing, querying and ranking. Suggest how big each chunk should be for my content, how to combine semantic and keyword search for names and codes, and how I can measure whether search results are good using [number] test queries.

More in Building with AI

Learn AI in the AI Compass app

Every guide and dictionary card is also in the AI Compass app, with saved items, search and “Try it” buttons that open chat, image or video with the example filled in. Reading is free; creating uses credits, and the price is shown before you start.