Skip to content

Instantly share code, notes, and snippets.

View saas-coder's full-sized avatar

Ninja saas-coder

  • Entrepreneur
  • Morocco
  • 18:36 (UTC -12:00)
View GitHub Profile

توضيح كود نظام الأسئلة والأجوبة (RAG)

في هذا المستند، سنقوم بشرح مفصل لكود نظام الأسئلة والأجوبة (RAG) المطبق في ملف Python. سنتناول كيفية عمل النظام من الأساسيات إلى التفاصيل التقنية، بما في ذلك تقسيم المستندات، التضمين (embedding)، ونظام البحث القائم على FAISS.

مقدمة

نظام الأسئلة والأجوبة (RAG) هو نظام يتعامل مع استخراج المعلومات من مستندات نصية للإجابة على الأسئلة بناءً على المحتوى المستخرج. يتضمن هذا النظام عدة خطوات أساسية: تحميل المستندات، تقسيم النصوص، إنشاء قاعدة بيانات بحثية، والتعامل مع نموذج ذكاء اصطناعي للإجابة على الأسئلة.

كيفية عمل نظام RAG

{
"data": [
{
"id": "m975975870876394",
"version": "v1",
"brand": {
"id": "m103697922099853",
"page_id": "103697922099853",
"name": "Investing Journal",
"avatar_url": "https://cdn.tryatria.com/adfiles/m975975870876394_vgOxxk9-W4M.jpeg",

Complete Example Structure

1. Create Main Marketing Folder

curl -X POST "https://mongo.fillcreative.io/api/folders/create" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "test",
    "name": "Marketing Campaigns 2024"
  }'
// Function to check if an ad has EU data without fetching the full data
async function checkEUDataEligibility(requestIndex, adID) {
// Check if we already have information about this ad
const collectionIndex = findCollectionIndex(adsCollections, adID);
if (collectionIndex === -1) return false;
const adIndex = findAdIndex(adsCollections[collectionIndex], adID);
if (adIndex === -1) return false;
const ad = adsCollections[collectionIndex][adIndex];
function initFacebookAdDownloader() {
// Queue to store pending GraphQL responses
const processingQueue = {
items: [],
isProcessing: false,
processDelay: 500, // Delay between processing items
async add(response) {
this.items.push(response);
if (!this.isProcessing) {