التضمينات وقواعد البيانات المتجهية
افهم كيف تحوّل تضمينات النص المعنى إلى متجهات، وكيف تتيح قواعد البيانات المتجهية خطوة الاسترجاع في صميم RAG.
التضمينات وقواعد البيانات المتجهية درس مجاني في LangChain / RAG / Vector DBs على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في LangChain / RAG / Vector DBs، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة LangChain / RAG / Vector DBs 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
From Words to Vectors
Computers cannot compare meaning directly. An embedding is a vector of numbers representing a text’s meaning, so similar texts land close together.
What an Embedding Looks Like
An embedding model maps text to a fixed-length vector with hundreds or thousands of dimensions. The numbers are not readable — what counts is their geometric relationships.
text = 'a cup of coffee'
embedding = [0.12, -0.04, 0.88, 0.31] # simplified
print('dimensions:', len(embedding))Semantic Similarity
Because meaning maps to position, "dog" sits near "puppy" but far from "database". That is what powers semantic search — matching by meaning, not exact keywords.
Measuring Closeness
The go-to closeness metric is cosine similarity — the cosine of the angle between two vectors. 1 means nearly identical, 0 means unrelated.
def cosine(a, b):
dot = sum(x*y for x, y in zip(a, b))
na = sum(x*x for x in a) ** 0.5
nb = sum(y*y for y in b) ** 0.5
return dot / (na * nb)
print(round(cosine([1, 0, 1], [1, 0, 1]), 2))
print(round(cosine([1, 0, 0], [0, 1, 0]), 2))Why a Vector Database?
RAG must find the most relevant chunks among millions of vectors, fast. A vector database stores embeddings and finds nearest neighbors — something SQL is not built for.
Approximate Nearest Neighbor
Comparing a query to every vector is too slow at scale. Vector DBs use ANN indexes like HNSW that trade a sliver of accuracy for huge speed gains.
Indexing Documents
To build a knowledge base, index your docs: split into chunks, embed each one, and store the vector with its text and metadata. This is RAG’s offline ingestion step.
chunks = ['intro paragraph', 'pricing details', 'support hours']
for c in chunks:
vec = embed(c) # call embedding model
db.upsert(vec, text=c)Querying
At query time, embed the user’s question with the same model, then ask the vector DB for the top-k nearest chunks — that becomes the LLM’s context.
q_vec = embed('when is support open?')
results = db.search(q_vec, top_k=3)
for r in results:
print(r.text, r.score)Metadata Filtering
Vector DBs also support metadata filtering: combine similarity search with filters like language, date range, or owner to sharpen relevance.
db.search(q_vec, top_k=3, filter={'lang': 'en', 'year': 2026})Choosing a Vector Store
Your vector store options span libraries (FAISS), dedicated DBs (Pinecone, Weaviate, Qdrant, Milvus), and extensions like pgvector. Pick by scale, hosting, and data needs.
Embeddings in the RAG Pipeline
Embeddings and the vector DB are the retrieval half of RAG: index once, then for every question embed, search, and hand the top chunks to the LLM as grounding.
Quick Check
Test your understanding of embeddings and vector search.
Recap
You learned RAG’s retrieval foundation: embeddings turn meaning into vectors, cosine measures closeness, and vector DBs use ANN for fast nearest-neighbor search.
الأسئلة الشائعة
هل درس «التضمينات وقواعد البيانات المتجهية» مجاني؟
نعم — نص درس «التضمينات وقواعد البيانات المتجهية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة LangChain / RAG / Vector DBs، انتقل إلى CoddyKit PRO. تتضمن دورة LangChain / RAG / Vector DBs 4 دروس في المجموع.
ماذا ستتعلم في «التضمينات وقواعد البيانات المتجهية»؟
افهم كيف تحوّل تضمينات النص المعنى إلى متجهات، وكيف تتيح قواعد البيانات المتجهية خطوة الاسترجاع في صميم RAG. تتمرن على LangChain / RAG / Vector DBs مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ LangChain / RAG / Vector DBs؟
لا تُشترط خبرة سابقة. LangChain / RAG / Vector DBs على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «التضمينات وقواعد البيانات المتجهية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس LangChain / RAG / Vector DBs هذا؟
نعم. كل درس في LangChain / RAG / Vector DBs يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- ما هي نماذج اللغة الكبيرة؟
- الحاجة إلى التوليد المعزّز بالاسترجاع
- المكوّنات الأساسية لنظام RAG
- التضمينات وقواعد البيانات المتجهية