How to Use Embedding Models with LLMs for Smarter AI Applications
In today’s AI landscape, Large Language Models (LLMs) like GPT-4, Llama-3, or Qwen2.5 grab all the headlines — but if you want them to work with your data, you need another type of model alongside them: embedding models.
In this post, we’ll explore what embeddings are, why they matter, and how to combine them with LLMs to build powerful applications like semantic search and Retrieval-Augmented Generation (RAG).
1. What is an Embedding Model?
An embedding model converts text (or other data) into a list of numbers — a vector — that captures the meaning of the content.
In this vector space, similar ideas are located close together, even if the exact words are different.
Example:
"dog" → [0.12, -0.09, 0.33, ...]
"puppy" → [0.11, -0.08, 0.31, ...] ← close in meaning
"airplane" → [-0.44, 0.88, 0.05, ...] ← far in meaning
Popular embedding models:
- OpenAI:
text-embedding-3-large(3072 dims),text-embedding-3-small(1536 dims) - Local:
mxbai-embed-large,all-MiniLM-L6-v2,Qwen3-Embedding-0.6B-GGUF - Multilingual:
embed-multilingual-v3.0(Cohere)
2. Why Pair Embeddings with LLMs?
LLMs are great at reasoning and generating text — but they can’t magically access your private data unless you feed it to them.
Embedding models solve this by enabling semantic retrieval from your data store.
This combination is the backbone of RAG:
- Embedding Model → Converts all your documents into vectors and stores them in a vector database.
- LLM → Uses your question, retrieves relevant chunks from the DB, and generates an answer using them.
3. The RAG Pipeline in Action
graph TD
A["User Question"] --> B["Embedding Model → Query Vector"]
B --> C["Vector DB → Find Similar Document Vectors"]
C --> D["Relevant Docs"]
D --> E["LLM → Combine Question + Docs → Final Answer"]
Step-by-step
Step 1: Preprocess & Store Documents
- Split documents into chunks (e.g., 500 tokens each).
- Use the embedding model to convert each chunk into a vector.
- Store vectors + metadata in a vector database (e.g., Qdrant, Milvus, Weaviate).
Step 2: Handle User Queries
- Convert the query into a vector using the same embedding model.
- Search for the nearest vectors in the DB.
- Retrieve the original text chunks.
Step 3: Generate the Answer
- Pass both the query and retrieved chunks into your LLM prompt.
- Let the LLM compose a coherent, accurate answer.
4. Code Example: OpenAI API + Qdrant + GPT-4
from openai import OpenAI
import qdrant_client
# Setup
client = OpenAI(api_key="YOUR_KEY")
qdrant = qdrant_client.QdrantClient(":memory:")
# 1. Embed a document
doc = "Durian is a tropical fruit grown in Southeast Asia."
embedding = client.embeddings.create(
model="text-embedding-3-large",
input=doc
).data[0].embedding
# Store in Qdrant
qdrant.recreate_collection("docs", vector_size=len(embedding))
qdrant.upsert("docs", [(0, embedding, {"text": doc})])
# 2. Embed a query
query = "Where is durian grown?"
query_vec = client.embeddings.create(
model="text-embedding-3-large",
input=query
).data[0].embedding
# Search
results = qdrant.search("docs", query_vec, limit=1)
context = results[0].payload["text"]
# 3. Ask the LLM with retrieved context
answer = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "Answer based on the provided context."},
{"role": "user", "content": f"Context: {context}\n\nQuestion: {query}"}
]
)
print(answer.choices[0].message["content"])
5. Best Practices
- Match the embedding model to your domain (multilingual if needed).
- Chunk size matters: too small = loss of context; too big = poor match quality.
- Keep embedding and query models the same for best similarity scoring.
- Use LLMs with long context windows if you plan to retrieve many chunks.
6. When to Use This Approach
- Knowledge base Q\&A
- Semantic search over large corpora
- Chatbots that “remember” your documents
- Contextual assistants in enterprise apps
Final Thought
The magic of combining embedding models with LLMs is that you get the precision of search and the fluency of generation in one pipeline.
That’s why nearly every serious AI-powered application — from ChatGPT Enterprise to local RAG bots — uses this two-model setup.
Get in Touch with us
Related Posts
- SimpliPOSFlex. 面向真实作业现场的 POS 系统(中国市场版)
- SimpliPOSFlex. The POS Designed for Businesses Where Reality Matters
- 经典编程思维 —— 向 Kernighan & Pike 学习
- Classic Programming Thinking: What We Still Learn from Kernighan & Pike
- 在开始写代码之前:我们一定会先问客户的 5 个问题
- Before Writing Code: The 5 Questions We Always Ask Our Clients
- 为什么“能赚钱的系统”未必拥有真正的价值
- Why Profitable Systems Can Still Have No Real Value
- 她的世界
- Her World
- Temporal × 本地大模型 × Robot Framework 面向中国企业的可靠业务自动化架构实践
- Building Reliable Office Automation with Temporal, Local LLMs, and Robot Framework
- RPA + AI: 为什么没有“智能”的自动化一定失败, 而没有“治理”的智能同样不可落地
- RPA + AI: Why Automation Fails Without Intelligence — and Intelligence Fails Without Control
- Simulating Border Conflict and Proxy War
- 先解决“检索与访问”问题 重塑高校图书馆战略价值的最快路径
- Fix Discovery & Access First: The Fastest Way to Restore the University Library’s Strategic Value
- 我们正在开发一个连接工厂与再生资源企业的废料交易平台
- We’re Building a Better Way for Factories and Recyclers to Trade Scrap
- 如何使用 Python 开发 MES(制造执行系统) —— 面向中国制造企业的实用指南













