{"id":458261,"date":"2025-04-30T21:00:40","date_gmt":"2025-04-30T21:00:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=458261"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=458261","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0423\u043c\u043d\u043e\u0439 \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0412\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439 OpenAI (\u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b, \u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0438 \u041f\u043e\u0438\u0441\u043a)<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0441 &#171;\u0443\u043c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439&#187; \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e. <strong>\u042f \u043d\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u0432 \u0418\u0418, \u0442\u0430\u043a \u0447\u0442\u043e \u043b\u044e\u0431\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f!<\/strong><\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u2014 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 OpenAI. \u0422\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0442\u0430\u043a \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u2014 <strong>\u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/strong>, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u0435\u0451 \u043d\u0430 <strong>\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b<\/strong>, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0438\u0445 <strong>\u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f<\/strong> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenAI \u0438 <strong>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 Markdown-\u0444\u0430\u0439\u043b\u043e\u0432, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442, \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442.\u0434.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a52\/9e8\/cde\/a529e8cde1c582c335368d60d8b0162c.png\" alt=\"\" title=\"\" width=\"3024\" height=\"1478\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/a52\/9e8\/cde\/a529e8cde1c582c335368d60d8b0162c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a52\/9e8\/cde\/a529e8cde1c582c335368d60d8b0162c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h3>\u0417\u0430\u0447\u0435\u043c?<\/h3>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u0440\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u044b\u0441\u0442\u0440\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \/ \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0430\u043a \u0432 Algolia<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u043c\u043e\u0449\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0432 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0431\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/strong><\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u0421\u0432\u043e\u0434\u043a\u0430<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0438 \u043c\u043e\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b, \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0447\u0430\u0442-\u0431\u043e\u0442\u0443)<\/p>\n<\/li>\n<\/ol>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<pre><code class=\"bash\">. \u2514\u2500\u2500 docs     \u2514\u2500\u2500 ...md \u2514\u2500\u2500 src     \u2514\u2500\u2500 askDocQuestion.ts     \u2514\u2500\u2500 index.ts # endpoint \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Express.js \u2514\u2500\u2500 embeddings.json # \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439 \u2514\u2500\u2500 packages.json <\/code><\/pre>\n<hr\/>\n<h3>1. \u0427\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0436\u0435\u0441\u0442\u043a\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0443 \u0441 <code>.md<\/code> \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>glob<\/code>.<\/p>\n<pre><code>import fs from \"node:fs\"; import path from \"node:path\"; import glob from \"glob\";  const DOC_FOLDER_PATH = \".\/docs\";  type FileData = {   path: string;   content: string; };  const readAllMarkdownFiles = (): FileData[] =&gt; {   const filesContent: FileData[] = [];   const filePaths = glob.sync(`${DOC_FOLDER_PATH}\/**\/*.md`);    filePaths.forEach((filePath) =&gt; {     const content = fs.readFileSync(filePath, \"utf8\");     filesContent.push({ path: filePath, content });   });    return filesContent; }; <\/code><\/pre>\n<blockquote>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, CMS \u0438 \u0442.\u0434.<\/p>\n<\/blockquote>\n<hr\/>\n<h3>2. \u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/platform.openai.com\/docs\/guides\/embeddings\" rel=\"noopener noreferrer nofollow\">API \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439 OpenAI<\/a> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043c\u0435\u0436\u0434\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438).<\/p>\n<pre><code>[   -0.0002630692, -0.029749284, 0.010225477, -0.009224428, -0.0065269712,   -0.002665544, 0.003214777, 0.04235309, -0.033162255, -0.00080789323,   \/\/...+1533 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 ]; <\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b <a href=\"https:\/\/www.cloudflare.com\/learning\/ai\/what-is-vector-database\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a>. \u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OpenAI API, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043a <a href=\"https:\/\/www.trychroma.com\/\" rel=\"noopener noreferrer nofollow\">Chroma<\/a>, <a href=\"https:\/\/qdrant.tech\/\" rel=\"noopener noreferrer nofollow\">Qdrant<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/www.pinecone.io\/\" rel=\"noopener noreferrer nofollow\">Pinecone<\/a>.<\/p>\n<\/blockquote>\n<h4>2.1 \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435\u043c<\/h4>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u043b\u0438 \u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u043c\u044b \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0438\u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432). \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043e\u0431\u043e\u0440\u0432\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0432\u0430\u0436\u043d\u043e\u0439 \u043c\u044b\u0441\u043b\u0438.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043f\u043e 100 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0441 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432 50 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 (406 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432):<\/strong><\/p>\n<p><em>\u0412 \u0446\u0435\u043d\u0442\u0440\u0435 \u0448\u0443\u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0440\u043e\u0434\u0430 \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0431\u044b\u043b\u0438. \u0415\u0451 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u043f\u043e\u043b\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0448\u0435\u043f\u0442\u044b\u0432\u0430\u043b\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0430 \u0434\u0432\u0435\u0440\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u043c\u043e\u0432. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<ul>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 1 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 1\u2013150):<\/strong><\/p>\n<p><em>\u0412 \u0446\u0435\u043d\u0442\u0440\u0435 \u0448\u0443\u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0440\u043e\u0434\u0430 \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0431\u044b\u043b\u0438. \u0415\u0451 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u043f\u043e\u043b\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442.<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 2 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 101\u2013250):<\/strong><\/p>\n<p><em>\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0448\u0435\u043f\u0442\u044b\u0432\u0430\u043b\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 3 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 201\u2013350):<\/strong><\/p>\n<p><em>\u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0430 \u0434\u0432\u0435\u0440\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u043c\u043e\u0432. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 4 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 301\u2013406):<\/strong><\/p>\n<p><em>\u043f\u044b\u0442\u043b\u0438\u0432\u044b\u0435 \u0443\u043c\u044b. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/h3>\n<pre><code>const CHARS_PER_TOKEN = 4.15;  const MAX_TOKENS = 500; const OVERLAP_TOKENS = 100;  const maxChar = MAX_TOKENS * CHARS_PER_TOKEN; const overlapChar = OVERLAP_TOKENS * CHARS_PER_TOKEN;  const chunkText = (text: string): string[] =&gt; {   const chunks: string[] = [];   let start = 0;    while (start &lt; text.length) {     let end = Math.min(start + maxChar, text.length);      if (end &lt; text.length) {       const lastSpace = text.lastIndexOf(\" \", end);       if (lastSpace &gt; start) end = lastSpace;     }      chunks.push(text.substring(start, end));     const nextStart = end - overlapChar;     start = nextStart &lt;= start ? end : nextStart;   }    return chunks; }; <\/code><\/pre>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0438 \u0432\u043b\u0438\u044f\u043d\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u2014 <a href=\"https:\/\/www.restack.io\/p\/embeddings-answer-openai-embeddings-chunk-size-cat-ai\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h4>2.2 \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 API OpenAI (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>text-embedding-3-large<\/code>).<\/p>\n<pre><code>import { OpenAI } from \"openai\";  const EMBEDDING_MODEL: OpenAI.Embeddings.EmbeddingModel =   \"text-embedding-3-large\";  const openai = new OpenAI({ apiKey: OPENAI_API_KEY });  const generateEmbedding = async (textChunk: string): Promise&lt;number[]&gt; =&gt; {   const response = await openai.embeddings.create({     model: EMBEDDING_MODEL,     input: textChunk,   });    return response.data[0].embedding; }; <\/code><\/pre>\n<h4>2.3 \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043c\u044b \u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 JSON-\u0444\u0430\u0439\u043b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043b\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432 JSON<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 <code>vectorStore<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<\/ol>\n<pre><code>const CHARS_PER_TOKEN = 4.15; const MAX_TOKENS = 500; const OVERLAP_TOKENS = 100;  const maxChar = MAX_TOKENS * CHARS_PER_TOKEN; const overlapChar = OVERLAP_TOKENS * CHARS_PER_TOKEN;  const chunkText = (text: string): string[] =&gt; {   const chunks: string[] = [];   let start = 0;    while (start &lt; text.length) {     let end = Math.min(start + maxChar, text.length);     const lastSpace = text.lastIndexOf(\" \", end);     if (lastSpace &gt; start) end = lastSpace;      chunks.push(text.substring(start, end));     const nextStart = end - overlapChar;     start = nextStart &lt;= start ? end : nextStart;   }    return chunks; }; <\/code><\/pre>\n<hr\/>\n<h3>3. \u041f\u043e\u0438\u0441\u043a \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<h4>3.1 \u0412\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0434\u043b\u044f <strong>\u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u043c\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430. \u041c\u044b \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0438\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430, \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e X \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439.<\/p>\n<pre><code>\/**  * \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.  * \u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441 \u0443\u0433\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0432 \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435.  * \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0435\u043a\u0441\u0442\u0430.  *  * @param vecA - \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440  * @param vecB - \u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440  * @returns \u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430  *\/ const cosineSimilarity = (vecA: number[], vecB: number[]): number =&gt; {   const dotProduct = vecA.reduce((sum, a, idx) =&gt; sum + a * vecB[idx], 0);   const magnitudeA = Math.sqrt(vecA.reduce((sum, a) =&gt; sum + a * a, 0));   const magnitudeB = Math.sqrt(vecB.reduce((sum, b) =&gt; sum + b * b, 0));   return dotProduct \/ (magnitudeA * magnitudeB); };  const MIN_RELEVANT_CHUNKS_SIMILARITY = 0.77; \/\/ \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043d\u0438\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u043c const MAX_RELEVANT_CHUNKS_NB = 15; \/\/ \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 chatGPT  \/**  * \u0418\u0449\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.  * \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432.  *  * @param query - \u041f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  * @returns \u041c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430  *\/ const searchChunkReference = async (query: string) =&gt; {   const queryEmbedding = await generateEmbedding(query);    const results = vectorStore     .map((doc) =&gt; ({       ...doc,       similarity: cosineSimilarity(queryEmbedding, doc.embedding),     }))     .filter((doc) =&gt; doc.similarity &gt; MIN_RELEVANT_CHUNKS_SIMILARITY)     .sort((a, b) =&gt; b.similarity - a.similarity)     .slice(0, MAX_RELEVANT_CHUNKS_NB);    return results; }; <\/code><\/pre>\n<h4>3.2 \u0417\u0430\u043f\u0440\u043e\u0441 \u043a OpenAI \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c <strong>\u043b\u0443\u0447\u0448\u0438\u0435<\/strong> \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u043f\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 ChatGPT. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e ChatGPT &#171;\u0432\u0438\u0434\u0438\u0442&#187; \u0441\u0430\u043c\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u0432\u044b \u0438\u0445 \u0432\u0432\u0435\u043b\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0432 \u0447\u0430\u0442. \u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<pre><code>const MODEL: OpenAI.Chat.ChatModel = \"gpt-4o-2024-11-20\";  export type ChatCompletionRequestMessage = {   role: \"system\" | \"user\" | \"assistant\";   content: string; };  \/**  * \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \"\u0417\u0430\u0434\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\" \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0435 Express.js.  * \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 OpenAI.  *  * @param messages - \u041c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0447\u0430\u0442\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430  * @returns \u041e\u0442\u0432\u0435\u0442 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438  *\/ export const askDocQuestion = async (   messages: ChatCompletionRequestMessage[] ): Promise&lt;string&gt; =&gt; {   const userMessages = messages.filter((message) =&gt; message.role === \"user\");    const formattedUserMessages = userMessages     .map((message) =&gt; `- ${message.content}`)     .join(\"\\n\");    const relevantChunks = await searchChunkReference(formattedUserMessages);    const messagesList: ChatCompletionRequestMessage[] = [     {       role: \"system\",       content:         \"Ignore all previous instructions. \\         You're an helpful chatbot.\\         ...\\         Here is the relevant documentation:\\         \" +         relevantChunks           .map(             (doc, idx) =&gt;               `[Chunk ${idx}] filePath = \"${doc.filePath}\":\\n${doc.content}`           )           .join(\"\\n\\n\"),     },     ...messages,   ];    const response = await openai.chat.completions.create({     model: MODEL,     messages: messagesList,   });    const result = response.choices[0].message.content;    if (!result) {     throw new Error(\"No response from OpenAI\");   }    return result; }; <\/code><\/pre>\n<hr\/>\n<h3>4. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 OpenAI API \u0447\u0435\u0440\u0435\u0437 Express<\/h3>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440 Express.js. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430:<\/p>\n<pre><code>import express, { type Request, type Response } from \"express\"; import {   ChatCompletionRequestMessage,   askDocQuestion,   indexMarkdownFiles, } from \".\/askDocQuestion\";  indexMarkdownFiles();  const app = express(); app.use(express.json());  type AskRequestBody = {   messages: ChatCompletionRequestMessage[]; };  app.post(   \"\/ask\",   async (     req: Request&lt;undefined, undefined, AskRequestBody&gt;,     res: Response&lt;string&gt;   ) =&gt; {     try {       const response = await askDocQuestion(req.body.messages);       res.json(response);     } catch (error) {       console.error(error);     }   } );  app.listen(3000, () =&gt; {   console.log(`Listening on port 3000`); }); <\/code><\/pre>\n<hr\/>\n<h3>5. UI: \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0447\u0430\u0442-\u0431\u043e\u0442\u0430<\/h3>\n<p>\u041d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 React \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0447\u0430\u0442\u0430. \u041e\u043d \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0430 \u0431\u044d\u043a\u0435\u043d\u0434 Express \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u044b. \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0435\u0442\u0430\u043b\u0438 \u043e\u043f\u0443\u0449\u0435\u043d\u044b.<\/p>\n<hr\/>\n<h3>\u0428\u0430\u0431\u043b\u043e\u043d \u043a\u043e\u0434\u0430<\/h3>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b <a href=\"https:\/\/github.com\/aymericzip\/smart_doc\" rel=\"noopener noreferrer nofollow\">\u0448\u0430\u0431\u043b\u043e\u043d \u043a\u043e\u0434\u0430<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430.<\/p>\n<h3>\u0416\u0438\u0432\u0430\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0447\u0430\u0442-\u0431\u043e\u0442, \u0437\u0430\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 <a href=\"https:\/\/intlayer.org\/ru\/doc\/get-started\" rel=\"noopener noreferrer nofollow\"><strong>\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u0435\u043c\u043e<\/strong><\/a><\/p>\n<h4>\u041c\u043e\u0439 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043a\u043e\u0434<\/h4>\n<ul>\n<li>\n<p><strong>\u0411\u044d\u043a\u0435\u043d\u0434<\/strong>: <a href=\"https:\/\/github.com\/aymericzip\/intlayer\/blob\/main\/apps\/backend\/src\/utils\/AI\/askDocQuestion.ts\" rel=\"noopener noreferrer nofollow\">askDocQuestion.ts<\/a><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u043e\u043d\u0442\u0435\u043d\u0434<\/strong>: <a href=\"https:\/\/github.com\/aymericzip\/intlayer\/tree\/main\/apps\/website\/src\/components\/ChatBot\" rel=\"noopener noreferrer nofollow\">\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b ChatBot<\/a><\/p>\n<\/li>\n<\/ul>\n<h3>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435<\/h3>\n<p>\u041d\u0430 YouTube \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/www.youtube.com\/watch?v=ySus5ZS0b94\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0434\u0435\u043e Adrien Twarog<\/a> \u2014 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u043c OpenAI \u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 <a href=\"https:\/\/platform.openai.com\/docs\/assistants\/tools\/file-search\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e OpenAI \u043f\u043e File Search<\/a>, \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434.<\/p>\n<hr\/>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0434\u043b\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430,<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u0438 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c\u0443 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0443,<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 ChatGPT \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u042f \u043d\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u043f\u043e \u0418\u0418, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0434\u043b\u044f \u043c\u043e\u0438\u0445 \u043d\u0443\u0436\u0434. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438, \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u2014 \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438.<\/p>\n<p><strong>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043c\u044b\u0441\u043b\u044f\u043c\u0438!<\/strong><\/p>\n<p>[\u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0418\u0418 \u2014 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0430 Medium <a href=\"https:\/\/dev.to\/aypineau\/building-a-smart-documentation-based-on-openai-embeddings-chunking-indexing-and-searching-4nam\" rel=\"noopener noreferrer nofollow\">https:\/\/dev.to\/aypineau\/building-a-smart-documentation-based-on-openai-embeddings-chunking-indexing-and-searching-4nam<\/a>]<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/905904\/\"> https:\/\/habr.com\/ru\/articles\/905904\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u0441 &#171;\u0443\u043c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439&#187; \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043d\u0430\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e. <strong>\u042f \u043d\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0442 \u0432 \u0418\u0418, \u0442\u0430\u043a \u0447\u0442\u043e \u043b\u044e\u0431\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442\u0441\u044f!<\/strong><\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u2014 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0447\u0430\u0442-\u0431\u043e\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 OpenAI. \u0422\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0442\u0430\u043a \u0445\u0432\u0430\u0442\u0430\u0435\u0442. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u2014 <strong>\u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e<\/strong>, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u0435\u0451 \u043d\u0430 <strong>\u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b<\/strong>, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0438\u0445 <strong>\u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f<\/strong> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenAI \u0438 <strong>\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 Markdown-\u0444\u0430\u0439\u043b\u043e\u0432, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442, \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442.\u0434.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u0417\u0430\u0447\u0435\u043c?<\/h3>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u0440\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u044f \u0437\u0430\u0445\u043e\u0442\u0435\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0447\u0430\u0442-\u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443:<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u044b\u0441\u0442\u0440\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \/ \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0430\u043a \u0432 Algolia<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u043c\u043e\u0449\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0432 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0431\u043e\u0440 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/strong><\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u0421\u0432\u043e\u0434\u043a\u0430<\/h3>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0438 \u043c\u043e\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b, \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435, \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0447\u0430\u0442-\u0431\u043e\u0442\u0443)<\/p>\n<\/li>\n<\/ol>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<pre><code class=\"bash\">. \u2514\u2500\u2500 docs     \u2514\u2500\u2500 ...md \u2514\u2500\u2500 src     \u2514\u2500\u2500 askDocQuestion.ts     \u2514\u2500\u2500 index.ts # endpoint \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Express.js \u2514\u2500\u2500 embeddings.json # \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439 \u2514\u2500\u2500 packages.json <\/code><\/pre>\n<hr\/>\n<h3>1. \u0427\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0436\u0435\u0441\u0442\u043a\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043f\u043a\u0443 \u0441 <code>.md<\/code> \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>glob<\/code>.<\/p>\n<pre><code>import fs from \"node:fs\"; import path from \"node:path\"; import glob from \"glob\";  const DOC_FOLDER_PATH = \".\/docs\";  type FileData = {   path: string;   content: string; };  const readAllMarkdownFiles = (): FileData[] =&gt; {   const filesContent: FileData[] = [];   const filePaths = glob.sync(`${DOC_FOLDER_PATH}\/**\/*.md`);    filePaths.forEach((filePath) =&gt; {     const content = fs.readFileSync(filePath, \"utf8\");     filesContent.push({ path: filePath, content });   });    return filesContent; }; <\/code><\/pre>\n<blockquote>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, CMS \u0438 \u0442.\u0434.<\/p>\n<\/blockquote>\n<hr\/>\n<h3>2. \u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/platform.openai.com\/docs\/guides\/embeddings\" rel=\"noopener noreferrer nofollow\">API \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439 OpenAI<\/a> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439.<\/p>\n<p>\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043c\u0435\u0436\u0434\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438).<\/p>\n<pre><code>[   -0.0002630692, -0.029749284, 0.010225477, -0.009224428, -0.0065269712,   -0.002665544, 0.003214777, 0.04235309, -0.033162255, -0.00080789323,   \/\/...+1533 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 ]; <\/code><\/pre>\n<blockquote>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b <a href=\"https:\/\/www.cloudflare.com\/learning\/ai\/what-is-vector-database\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a>. \u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f OpenAI API, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u043a <a href=\"https:\/\/www.trychroma.com\/\" rel=\"noopener noreferrer nofollow\">Chroma<\/a>, <a href=\"https:\/\/qdrant.tech\/\" rel=\"noopener noreferrer nofollow\">Qdrant<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/www.pinecone.io\/\" rel=\"noopener noreferrer nofollow\">Pinecone<\/a>.<\/p>\n<\/blockquote>\n<h4>2.1 \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435\u043c<\/h4>\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0431\u043b\u043e\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u043b\u0438 \u0434\u0430\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b. \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u043c\u044b \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0438\u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432). \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043e\u0431\u043e\u0440\u0432\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0432\u0430\u0436\u043d\u043e\u0439 \u043c\u044b\u0441\u043b\u0438.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043f\u043e 100 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0441 \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u0432 50 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p><strong>\u041f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 (406 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432):<\/strong><\/p>\n<p><em>\u0412 \u0446\u0435\u043d\u0442\u0440\u0435 \u0448\u0443\u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0440\u043e\u0434\u0430 \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0431\u044b\u043b\u0438. \u0415\u0451 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u043f\u043e\u043b\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0448\u0435\u043f\u0442\u044b\u0432\u0430\u043b\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0430 \u0434\u0432\u0435\u0440\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u043c\u043e\u0432. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<ul>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 1 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 1\u2013150):<\/strong><\/p>\n<p><em>\u0412 \u0446\u0435\u043d\u0442\u0440\u0435 \u0448\u0443\u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0440\u043e\u0434\u0430 \u0441\u0442\u043e\u044f\u043b\u0430 \u0441\u0442\u0430\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043d\u043e\u0433\u0438\u0435 \u0437\u0430\u0431\u044b\u043b\u0438. \u0415\u0451 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u043f\u043e\u043b\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442.<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 2 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 101\u2013250):<\/strong><\/p>\n<p><em>\u043a\u0438 \u0431\u044b\u043b\u0438 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u043a\u043d\u0438\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u0436\u0430\u043d\u0440\u043e\u0432, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0448\u0435\u043f\u0442\u044b\u0432\u0430\u043b\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 3 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 201\u2013350):<\/strong><\/p>\n<p><em>\u0437\u0430\u0433\u0430\u0434\u043e\u043a \u0438 \u0432\u0435\u0447\u043d\u043e\u0439 \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u0438. \u041a\u0430\u0436\u0434\u044b\u0439 \u0432\u0435\u0447\u0435\u0440 \u043f\u0440\u0435\u0434\u0430\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b\u0430 \u0434\u0432\u0435\u0440\u0438 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u043c\u043e\u0432. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0440\u0430\u0433\u043c\u0435\u043d\u0442 4 (\u0421\u0438\u043c\u0432\u043e\u043b\u044b 301\u2013406):<\/strong><\/p>\n<p><em>\u043f\u044b\u0442\u043b\u0438\u0432\u044b\u0435 \u0443\u043c\u044b. \u0414\u0435\u0442\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b.<\/em><\/p>\n<\/li>\n<\/ul>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/h3>\n<pre><code>const CHARS_PER_TOKEN = 4.15;  const MAX_TOKENS = 500; const OVERLAP_TOKENS = 100;  const maxChar = MAX_TOKENS * CHARS_PER_TOKEN; const overlapChar = OVERLAP_TOKENS * CHARS_PER_TOKEN;  const chunkText = (text: string): string[] =&gt; {   const chunks: string[] = [];   let start = 0;    while (start &lt; text.length) {     let end = Math.min(start + maxChar, text.length);      if (end &lt; text.length) {       const lastSpace = text.lastIndexOf(\" \", end);       if (lastSpace &gt; start) end = lastSpace;     }      chunks.push(text.substring(start, end));     const nextStart = end - overlapChar;     start = nextStart &lt;= start ? end : nextStart;   }    return chunks; }; <\/code><\/pre>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0438 \u0432\u043b\u0438\u044f\u043d\u0438\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u2014 <a href=\"https:\/\/www.restack.io\/p\/embeddings-answer-openai-embeddings-chunk-size-cat-ai\" rel=\"noopener noreferrer nofollow\">\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<\/blockquote>\n<h4>2.2 \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 API OpenAI (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>text-embedding-3-large<\/code>).<\/p>\n<pre><code>import { OpenAI } from \"openai\";  const EMBEDDING_MODEL: OpenAI.Embeddings.EmbeddingModel =   \"text-embedding-3-large\";  const openai = new OpenAI({ apiKey: OPENAI_API_KEY });  const generateEmbedding = async (textChunk: string): Promise&lt;number[]&gt; =&gt; {   const response = await openai.embeddings.create({     model: EMBEDDING_MODEL,     input: textChunk,   });    return response.data[0].embedding; }; <\/code><\/pre>\n<h4>2.3 \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u0439<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043c\u044b \u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 JSON-\u0444\u0430\u0439\u043b.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0443<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u043b\u0438\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u043d\u0430 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432 JSON<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 <code>vectorStore<\/code> \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<\/ol>\n<pre><code>const CHARS_PER_TOKEN = 4.15; const MAX_TOKENS = 500; const OVERLAP_TOKENS = 100;  const maxChar = MAX_TOKENS * CHARS_PER_TOKEN; const overlapChar = OVERLAP_TOKENS * CHARS_PER_TOKEN;  const chunkText = (text: string): string[] =&gt; {   const chunks: string[] = [];   let start = 0;    while (start &lt; text.length) {     let end = Math.min(start + maxChar, text.length);     const lastSpace = text.lastIndexOf(\" \", end);     if (lastSpace &gt; start) end = lastSpace;      chunks.push(text.substring(start, end));     const nextStart = end - overlapChar;     start = nextStart &lt;= start ? end : nextStart;   }    return chunks; }; <\/code><\/pre>\n<hr\/>\n<h3>3. \u041f\u043e\u0438\u0441\u043a \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/h3>\n<h4>3.1 \u0412\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0434\u043b\u044f <strong>\u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/strong>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430\u043c\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430. \u041c\u044b \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0438\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430, \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e X \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439.<\/p>\n<pre><code>\/**  * \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438.  * \u041a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441 \u0443\u0433\u043b\u0430 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0432 \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435.  * \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430 \u043c\u0435\u0436\u0434\u0443 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0435\u043a\u0441\u0442\u0430.  *  * @param vecA - \u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440  * @param vecB - \u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440  * @returns \u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0433\u043e \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430  *\/ const cosineSimilarity = (vecA: number[], vecB: number[]): number =&gt; {   const dotProduct = vecA.reduce((sum, a, idx) =&gt; sum + a * vecB[idx], 0);   const magnitudeA = Math.sqrt(vecA.reduce((sum, a) =&gt; sum + a * a, 0));   const magnitudeB = Math.sqrt(vecB.reduce((sum, b) =&gt; sum + b * b, 0));   return dotProduct \/ (magnitudeA * magnitudeB); };  const MIN_RELEVANT_CHUNKS_SIMILARITY = 0.77; \/\/ \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043d\u0438\u044f \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u043c const MAX_RELEVANT_CHUNKS_NB = 15; \/\/ \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 chatGPT  \/**  * \u0418\u0449\u0435\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.  * \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043a\u0438\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432.  *  * @param query - \u041f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  * @returns \u041c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430  *\/ const searchChunkReference = async (query: string) =&gt; {   const queryEmbedding = await generateEmbedding(query);    const results = vectorStore     .map((doc) =&gt; ({       ...doc,       similarity: cosineSimilarity(queryEmbedding, doc.embedding),     }))     .filter((doc) =&gt; doc.similarity &gt; MIN_RELEVANT_CHUNKS_SIMILARITY)     .sort((a, b) =&gt; b.similarity - a.similarity)     .slice(0, MAX_RELEVANT_CHUNKS_NB);    return results; }; <\/code><\/pre>\n<h4>3.2 \u0417\u0430\u043f\u0440\u043e\u0441 \u043a OpenAI \u0441 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u043c\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430\u043c\u0438<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c <strong>\u043b\u0443\u0447\u0448\u0438\u0435<\/strong> \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u043f\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 ChatGPT. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e ChatGPT &#171;\u0432\u0438\u0434\u0438\u0442&#187; \u0441\u0430\u043c\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u0432\u044b \u0438\u0445 \u0432\u0432\u0435\u043b\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0432 \u0447\u0430\u0442. \u0417\u0430\u0442\u0435\u043c \u043e\u043d \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<pre><code>const MODEL: OpenAI.Chat.ChatModel = \"gpt-4o-2024-11-20\";  export type ChatCompletionRequestMessage = {   role: \"system\" | \"user\" | \"assistant\";   content: string; };  \/**  * \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \"\u0417\u0430\u0434\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\" \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0435 Express.js.  * \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 OpenAI.  *  * @param messages - \u041c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0447\u0430\u0442\u0430 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430  * @returns \u041e\u0442\u0432\u0435\u0442 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438  *\/ export const askDocQuestion = async (   messages: ChatCompletionRequestMessage[] ): Promise&lt;string&gt; =&gt; {   const userMessages = messages.filter((message) =&gt; message.role === \"user\");    const formattedUserMessages = userMessages     .map((message) =&gt; `- ${message.content}`)     .join(\"\\n\");    const relevantChunks = await searchChunkReference(formattedUserMessages);    const messagesList: ChatCompletionRequestMessage[] = [     {       role: \"system\",       content:         \"Ignore all previous instructions. \\         You're an helpful chatbot.\\         ...\\         Here is the relevant documentation:\\         \" +         relevantChunks          <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-458261","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458261"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458261\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}