{
 "name": "S11 - KB Chat",
 "flow": [
  {
   "id": 1,
   "module": "gateway:CustomWebHook",
   "version": 1,
   "parameters": {
    "hook": null,
    "maxResults": 1
   },
   "mapper": {},
   "metadata": {
    "designer": {
     "x": 0,
     "y": 0,
     "name": "שאלה"
    }
   }
  },
  {
   "id": 2,
   "module": "http:ActionSendDataAPIKeyAuth",
   "version": 3,
   "parameters": {
    "key": null
   },
   "mapper": {
    "url": "https://api.openai.com/v1/embeddings",
    "serializeUrl": false,
    "method": "post",
    "headers": [],
    "qs": [],
    "bodyType": "raw",
    "contentType": "application/json",
    "data": "{\"model\": \"text-embedding-3-small\", \"input\": {{toString(1.q)}}}",
    "parseResponse": true,
    "authUser": "",
    "authPass": "",
    "timeout": "",
    "shareCookies": false,
    "ca": "",
    "rejectUnauthorized": true,
    "followRedirect": true,
    "useQuerystring": false,
    "gzip": true,
    "useMtls": false,
    "followAllRedirects": false
   },
   "metadata": {
    "designer": {
     "x": 300,
     "y": 0,
     "name": "Embedding לשאלה"
    }
   }
  },
  {
   "id": 3,
   "module": "http:ActionSendDataAPIKeyAuth",
   "version": 3,
   "parameters": {
    "key": null
   },
   "mapper": {
    "url": "https://REPLACE_INDEX_HOST/query",
    "serializeUrl": false,
    "method": "post",
    "headers": [],
    "qs": [],
    "bodyType": "raw",
    "contentType": "application/json",
    "data": "{\"vector\": {{toString(2.data.data[1].embedding)}}, \"topK\": 4, \"includeMetadata\": true}",
    "parseResponse": true,
    "authUser": "",
    "authPass": "",
    "timeout": "",
    "shareCookies": false,
    "ca": "",
    "rejectUnauthorized": true,
    "followRedirect": true,
    "useQuerystring": false,
    "gzip": true,
    "useMtls": false,
    "followAllRedirects": false
   },
   "metadata": {
    "designer": {
     "x": 600,
     "y": 0,
     "name": "Pinecone Query Top 4"
    }
   }
  },
  {
   "id": 4,
   "module": "builtin:BasicFeeder",
   "version": 1,
   "parameters": {},
   "mapper": {
    "array": "{{3.data.matches}}"
   },
   "metadata": {
    "designer": {
     "x": 900,
     "y": 0,
     "name": "Iterator matches"
    }
   }
  },
  {
   "id": 5,
   "module": "util:TextAggregator",
   "version": 1,
   "parameters": {
    "feeder": 4,
    "rowSeparator": "\n\n"
   },
   "mapper": {
    "value": "[{{4.metadata.source}}] {{4.metadata.text}}"
   },
   "metadata": {
    "designer": {
     "x": 1200,
     "y": 0,
     "name": "הקשר עם מקורות"
    }
   },
   "filter": {
    "name": "score ≥ 0.75",
    "conditions": [
     [
      {
       "a": "{{4.score}}",
       "o": "greaterOrEqual",
       "b": "0.75"
      }
     ]
    ]
   }
  },
  {
   "id": 6,
   "module": "openai-gpt-3:CreateCompletion",
   "version": 1,
   "parameters": {
    "__IMTCONN__": null
   },
   "mapper": {
    "select": "chat",
    "model": "gpt-4.1-mini",
    "temperature": "0.2",
    "max_tokens": "600",
    "messages": [
     {
      "role": "system",
      "content": "ענה רק לפי הקטעים. אם אין תשובה — כתוב \"לא מצאתי מידע על זה במסמכים\". בסוף: \"מקורות:\" ושמות הקבצים."
     },
     {
      "role": "user",
      "content": "קטעים:\n{{5.text}}\n\nשאלה: {{1.q}}"
     }
    ]
   },
   "metadata": {
    "designer": {
     "x": 1500,
     "y": 0,
     "name": "תשובה מהקטעים"
    }
   }
  },
  {
   "id": 7,
   "module": "gateway:WebhookRespond",
   "version": 1,
   "parameters": {},
   "mapper": {
    "status": "200",
    "body": "{\"answer\": {{toString(6.choices[].message.content)}}}",
    "headers": [
     {
      "key": "Content-Type",
      "value": "application/json; charset=utf-8"
     }
    ]
   },
   "metadata": {
    "designer": {
     "x": 1800,
     "y": 0,
     "name": "תשובה"
    }
   }
  }
 ],
 "metadata": {
  "instant": true,
  "version": 1,
  "scenario": {
   "roundtrips": 1,
   "maxErrors": 3,
   "autoCommit": true,
   "autoCommitTriggerLast": true,
   "sequential": false,
   "slots": null,
   "confidential": false,
   "dataloss": false,
   "dlq": true,
   "freshVariables": false
  },
  "designer": {
   "orphans": []
  },
  "zone": "eu1.make.com"
 }
}