انتقل إلى المحتوى
أمين أبوزيد
MID-067

التضمينات والبحث المتجهي

  • 6 درس
  • 3 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • التضمينات (Embeddings)
  • مقاييس التشابه
  • pgvector
  • فهارس HNSW وIVFFlat
  • البحث الهجين بالكلمات المفتاحية والمتجهات

تعلّم أولًا

3 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain what an embedding is and why semantically similar texts end up close together.
  2. Choose a similarity measure (cosine, inner product, Euclidean distance) consistent with the embedding model.
  3. Store and query embeddings in PostgreSQL with pgvector, and choose between HNSW and IVFFlat indexes by recall, build time, and memory.
  4. Combine keyword (full-text) and vector search into hybrid search and explain when each wins.

الدروس

  1. 01ما هي التضمينات
  2. 02مقاييس التشابه
  3. 03pgvector: تخزين المتجهات والاستعلام عنها
  4. 04الفهارس التقريبية: HNSW وIVFFlat
  5. 05البحث الهجين: الكلمات المفتاحية مع المتجهات
  6. 06عرض عملي: بحث دلالي في مقالات مركز مساعدة Shop

المختبر والتمارين

Lab

MID-067-LAB1 · Searchable help center

Outcomes: 1–4 · Time: ~3 h Embed Shop's help-center and policy documents into pgvector, add an HNSW index, and expose a semantic search endpoint with a hybrid (full-text + vector) mode. Prepare a test set of 30 customer questions with the expected article for each. Record query latency and index size. Acceptance: the right article is in the top 3 for at least 25 of the 30 questions; query latency and index size recorded.

Exercises (assessment: design exercise)

IDOutcomeTask
MID-067-EX011Explain why "refund my order" and "money back for a purchase" are close as vectors, and name one case where embeddings fail.
MID-067-EX022A model documents cosine similarity and returns normalized vectors. Choose the operator and operator class and justify.
MID-067-EX033Write the table, an HNSW index, and a top-5 query with a language filter for a 768-dimension model.
MID-067-EX043Choose HNSW or IVFFlat for (a) 50 000 chunks updated daily, (b) 20 M chunks rebuilt monthly; compare recall, build time, memory.
MID-067-EX054Give three Shop queries and say whether keyword, vector, or hybrid wins for each.
MID-067-EX063Design exercise: for a new corpus (10 000 product manuals, 4 languages) choose model, dimensions, index, and refresh strategy and justify each.
أظهر الحلول
  • EX01 The model maps similar meaning to nearby points. Failure: exact identifiers (SKUs, order numbers) or negation ("not refundable") may be missed.
  • EX02 Cosine distance <=> with vector_cosine_ops; for normalized vectors inner product gives the same ranking. Use the measure the model documents.
  • EX03 CREATE TABLE ... embedding vector(768); CREATE INDEX ... USING hnsw (embedding vector_cosine_ops); WHERE lang = 'ar' ORDER BY embedding <=> :q LIMIT 5. Verify syntax for your pgvector version.
  • EX04 (a) HNSW: handles inserts without rebuild and gives good recall; memory is small at this size. (b) Depends on the memory budget: IVFFlat builds faster and is smaller (build after load, tune lists and probes); HNSW usually has better recall. Measure recall for both.
  • EX05 "Where is my parcel": vector. "ORD-88231 status": keyword. "Return policy for electronics": hybrid.
  • EX06 Multilingual model if queries cross languages; dimensions as the model provides; HNSW with cosine; store model and content_hash; refresh only changed documents (hash compare) and re-embed everything only on a model change. Justify each with recall measured on a question set. Verify model choice and prices before deciding.

Outcomes 1 and 4 are also covered by the quiz and the lab (hybrid mode).

الاختبار

Outcomes: O1 embeddings · O2 similarity measures · O3 pgvector and indexes · O4 hybrid search.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1An embedding is:O1
  2. 2Mixing vectors from two models in one column is a mistake because:O1
  3. 3Embeddings are weakest for:O1
  4. 4Which distance measure should you choose?O2
  5. 5For normalized vectors, inner product ranks like:O2
  6. 6The pgvector column type for 768 dimensions:O3
  7. 7Compared with IVFFlat, HNSW usually has:O3
  8. 8Before trusting an approximate index you should:O3
  9. 9Reciprocal Rank Fusion merges results by:O4
  10. 10Which finds "ORD-88231" best?O4

الجزء العملي

Design exercise (MID-067-EX06) plus lab MID-067-LAB1. Pass: quiz at least 8/10, justified model, index, and refresh choices, and a lab with at least 25 of 30 questions answered in the top 3 and latency and index size recorded.

أخطاء شائعة

Mixing embeddings from different models in one column; using a distance measure the model was not trained for; approximate indexes without measuring recall; re-embedding everything on every change.

التقييم

Design exercise — choose model, dimensions, index, and refresh strategy for a new corpus and justify each choice.

الصلة بالمسار الوظيفي

The data layer of every RAG feature (MID-068) and of AI solution architectures (ARC-045).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.