{"id":468541,"date":"2025-07-25T15:02:07","date_gmt":"2025-07-25T15:02:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=468541"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=468541","title":{"rendered":"<span>\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448: \u0434\u0435\u043b\u0430\u0435\u043c \u0443\u043c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435<\/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<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/27c\/89a\/d2f\/27c89ad2faeaa20b7898cabd841c70e3.png\" width=\"1536\" height=\"1024\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/27c\/89a\/d2f\/27c89ad2faeaa20b7898cabd841c70e3.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/27c\/89a\/d2f\/27c89ad2faeaa20b7898cabd841c70e3.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u044b \u0438 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u044b \u0448\u0438\u0440\u043e\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0444\u0435\u0440\u0430\u0445: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445.\u00a0 \u0414\u043b\u044f \u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 Retrieval-Augmented Generation (RAG), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0431\u043e\u0442\u0430\u043c \u0438 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430\u043c \u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e RAG \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043f\u043e\u0432\u044b\u0448\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u043b\u0438\u043a\u0430.<\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u0430\u0434\u0438\u043c, \u044f Data Scientist \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Raft, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c!<\/p>\n<h2>\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 RAG<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0431\u0430\u0437\u043e\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 RAG. \u0412 \u0446\u0435\u043b\u043e\u043c \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 2 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (Data Indexing)<\/strong>: \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0431\u043e\u0440, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u043d\u0438\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0438\u0441\u043a \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 (Data Retrieval &amp; Generation)<\/strong>: \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0438\u0449\u0435\u0442 top-K \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 (chunks) \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.\u00a0 \u0414\u0430\u043b\u0435\u0435, \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, LLM \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/571\/9d0\/9f0\/5719d09f020c715ab2037c0087f343d9.png\" alt=\"\" title=\"\" width=\"700\" height=\"331\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/571\/9d0\/9f0\/5719d09f020c715ab2037c0087f343d9.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/571\/9d0\/9f0\/5719d09f020c715ab2037c0087f343d9.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 RAG <\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b <\/h2>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 RAG, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 <u>\u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430<\/u> \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430 \u0441\u0447\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f, \u043c\u043e\u0434\u0435\u043b\u0435\u0439 reranker-\u043e\u0432 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u041d\u043e \u0443 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0435\u0441\u0442\u044c \u043e\u0431\u0449\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c: \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 <u>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/u> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0445 \u0438\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0436\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043a\u043e\u043b\u043e <strong>30%<\/strong> \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043d\u043e\u0432\u043e \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0438\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438\u00a0 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c?<\/h2>\n<h3>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448?<\/h3>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u2014 \u044d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u00bb (\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443) \u043f\u043e\u0445\u043e\u0436\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0437\u0430\u043d\u043e\u0432\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442: \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0441\u044f \u043b\u0438 \u0443\u0436\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441? \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u043c\u0438\u043d\u0443\u044f \u043b\u0438\u0448\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0412 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043a\u044d\u0448\u0430.\u00a0<\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u00a0\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u00a0\u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u00a0\u2014 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0449\u0435\u043c \u0432 \u043a\u044d\u0448\u0435 \u043e\u0442\u0432\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u0440\u0435\u0434\u0438 \u0443\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u0438\u00a0 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u044c \u2014 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436, \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u044d\u0448 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/170\/6a7\/6d6\/1706a76d6b29b9d18faa353230298e6a.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b RAG \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c\" title=\"\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b RAG \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c\" width=\"1600\" height=\"966\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/170\/6a7\/6d6\/1706a76d6b29b9d18faa353230298e6a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/170\/6a7\/6d6\/1706a76d6b29b9d18faa353230298e6a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b RAG \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c<\/figcaption><\/div>\n<\/figure>\n<h3>\u0412\u0430\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432: \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043c\u0435\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438: \u0440\u0435\u0448\u0430\u0435\u043c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c \u00ab\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u044c\u00bb \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e <em>\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e <\/em>\u0438\u043b\u0438<em> \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/em>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u043e\u0433\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430: \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u044d\u0448. \u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0440\u043e\u0433 <em>\u043c\u0435\u043d\u044c\u0448\u0435 0.5<\/em><strong>.<\/strong>\u00a0<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 TTL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043a\u044d\u0448\u0430, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a LRU, FIFO, LFU \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u0445\u0435\u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/83f\/c08\/9fd\/83fc089fd77b091dcd5757a0505f5824.png\" width=\"512\" height=\"436\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/83f\/c08\/9fd\/83fc089fd77b091dcd5757a0505f5824.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/83f\/c08\/9fd\/83fc089fd77b091dcd5757a0505f5824.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043d\u0443\u043b\u044f<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 json \u0444\u0430\u0439\u043b\u0435 (\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0432\u0438\u0434\u0435 <a href=\"https:\/\/github.com\/infoslack\/qdrant-example\/blob\/main\/semantic-cache.ipynb\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439<\/a> \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043a\u044d\u0448\u0435\u043c\u00a0\u2014 <strong>SemanticCache<\/strong> \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430, \u043f\u043e\u0440\u043e\u0433 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435. \u0417\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u044f FIFO (First-In, First-Out) \u2014 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c\u0438.<\/p>\n<pre><code class=\"python\">class SemanticCache:     def __init__(self, json_file: str = \"cache_file.json\", threshold: float = 0.35,                  max_response: int = 100, eviction_policy: Optional[str] = None, nprobe: int = 8):         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u044d\u0448\u0430.          Args:             json_file (str): \u041f\u0443\u0442\u044c \u043a JSON \u0444\u0430\u0439\u043b\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430.             threshold (float): \u041f\u043e\u0440\u043e\u0433 \u0415\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043d\u0438\u0436\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438.             max_response (int): \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u044d\u0448\u0435.             eviction_policy (str, optional): \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 'FIFO').             nprobe (int): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 Faiss.         \"\"\"         # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c Faiss-\u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u044d\u043d\u043a\u043e\u0434\u0435\u0440         self.index, self.encoder = init_cache()          self.threshold = threshold         self.json_file = json_file         self.max_response = max_response         self.eviction_policy = eviction_policy         self.nprobe = nprobe          # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043a\u044d\u0448 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442         self.cache = retrieve_cache(self.json_file) <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u043c\u0435\u0442\u043e\u0434 <strong>search_in_cache<\/strong>, \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u043a\u044d\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043d\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Faiss \u0438\u0449\u0435\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043d\u0435\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430, \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u00a0\u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <strong>None<\/strong>.<\/p>\n<pre><code class=\"python\">def _search_in_cache(self, embedding: List[float]) -&gt; Optional[str]:         \"\"\"         \u0418\u0449\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Faiss-\u0438\u043d\u0434\u0435\u043a\u0441\u0435.          Args:             embedding (List[float]): \u0412\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.          Returns:             Optional[str]: \u041d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u043b\u0438\u0431\u043e None, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0442.         \"\"\"         # \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430         self.index.nprobe = self.nprobe          # \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0441\u043e\u0441\u0435\u0434\u0430         D, I = self.index.search(embedding, 1)         distance = D[0][0]         index = I[0][0]          # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0434 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f         if index &gt;= 0 and distance &lt;= self.threshold:             return self.cache['response_text'][index]          # \u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e         return None  <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u044d\u0448 \u043d\u0435 \u0440\u043e\u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <strong>_evict_if_needed, <\/strong>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 <strong>max_response<\/strong>, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0445 \u043f\u0435\u0440\u0432\u044b\u0445 (\u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0430\u0440\u044b\u0445) \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">def _evict_if_needed(self):         \"\"\"         \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439,         \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438.         \"\"\"         overflow = len(self.cache[\"questions\"]) - self.max_response         if overflow &gt; 0:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0432\u0441\u0435\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043a\u044d\u0448 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c             self.cache[\"questions\"] = self.cache[\"questions\"][overflow:]             self.cache[\"embeddings\"] = self.cache[\"embeddings\"][overflow:]             self.cache[\"answers\"] = self.cache[\"answers\"][overflow:]             self.cache[\"response_text\"] = self.cache[\"response_text\"][overflow:] <\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 <strong>ask<\/strong> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<ul>\n<li>\n<p> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433;<\/p>\n<\/li>\n<li>\n<p> \u0438\u0449\u0435\u0442 \u0432 \u043a\u044d\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441;<\/p>\n<\/li>\n<li>\n<p> \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442, \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u2014 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0445 \u0432 \u043a\u044d\u0448 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def ask(self, question: str, k: int) -&gt; str:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430 \u0438\u043b\u0438, \u0435\u0441\u043b\u0438 \u0432 \u043a\u044d\u0448\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, chromaDB).          Args:             question (str): \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.             k (int): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u043f\u0440\u0438 \u043f\u0440\u043e\u043c\u0430\u0445\u0435 \u043a\u044d\u0448\u0430.          Returns:             str: \u0422\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430.         \"\"\"         try:             # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440             embedding = self.encoder.encode([question])              # \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043a\u044d\u0448\u0435             cached_response = self._search_in_cache(embedding)              if cached_response:                 # \u0415\u0441\u043b\u0438 \u043d\u0430\u0448\u043b\u0438 \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e                 return cached_response              # \u0415\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u043b\u0438 \u2014 \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u0435             answers = query_database(question, k)              # \u0421\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442             response_text = \"\".join(doc.page_content for doc in answers)              # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u0442\u0432\u0435\u0442 \u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0432 \u043a\u044d\u0448             self.cache['questions'].append(question)             self.cache['embeddings'].append(embedding[0].tolist())             self.cache['answers'].append(response_text)             self.cache['response_text'].append(response_text)              # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0432 Faiss-\u0438\u043d\u0434\u0435\u043a\u0441             self.index.add(embedding)              # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u043b\u0438 \u043a\u044d\u0448, \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438             if len(self.cache[\"questions\"]) &gt; self.max_response:                 self._evict_if_needed()              # \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u044d\u0448 \u0432 \u0444\u0430\u0439\u043b             store_cache(self.json_file, self.cache)             return response_text          except Exception as e:             raise RuntimeError(f\"Error in 'ask' method: {e}\") <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u0430\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0433\u0438\u0431\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u044b. <\/p>\n<p>\u041d\u043e \u0437\u0430\u0447\u0435\u043c \u043d\u0430\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u0441 \u043d\u0443\u043b\u044f? \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Redis.<\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Redis<\/h4>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/52b\/e73\/1e6\/52be731e61843886db915d9e73d089fc.png\" width=\"747\" height=\"413\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/52b\/e73\/1e6\/52be731e61843886db915d9e73d089fc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/52b\/e73\/1e6\/52be731e61843886db915d9e73d089fc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><a href=\"https:\/\/redis.io\/\" rel=\"noopener noreferrer nofollow\">Redis<\/a> \u2014 \u044d\u0442\u043e \u0432\u044b\u0441\u043e\u043a\u043e\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (in-memory database), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u00ab\u043a\u043b\u044e\u0447\u2013\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445: \u0441\u043f\u0438\u0441\u043a\u0438, \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u0445\u0435\u0448\u0438, \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0440\u0430\u0431\u043e\u0442\u0435 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 Redis \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b GenAI, \u0441\u0440\u0435\u0434\u0438 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0435\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c (\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c) \u043a\u044d\u0448\u0435\u043c. \u0414\u043b\u044f \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/redis\/redis-vl-python\" rel=\"noopener noreferrer nofollow\">redisvl<\/a> \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u044d\u0448\u0435\u043c, \u043a\u043b\u0430\u0441\u0441 <strong>SemanticCache, <\/strong>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432 Redis,<\/p>\n<\/li>\n<li>\n<p>\u0430\u0434\u0440\u0435\u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430,<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u0440\u043e\u0433 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438 (distance_threshold),<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043a\u044d\u0448\u0430 (ttl).<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">from redisvl.extensions.cache.llm import SemanticCache from redisvl.utils.vectorize import HFTextVectorizer  llmcache = SemanticCache(    name=\"llmcache\",                                          # \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430    redis_url=\"redis:\/\/localhost:6379\",                       # URL \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a Redis    distance_threshold=0.1,                                   # \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u044d\u0448\u0430    vectorizer=HFTextVectorizer(\"redis\/langcache-embed-v1\"),  # \u043c\u043e\u0434\u0435\u043b\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432    overwrite=True,    ttl= 60 * 60 * 24,   # \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u044d\u0448\u0435 (1 \u0434\u0435\u043d\u044c) ) <\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442 Redis.<\/p>\n<pre><code class=\"python\">def process_query(question, k, vector_store, llmcache):      # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043a\u044d\u0448\u0435 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430     response = llmcache.check(question)      if response:         # \u0415\u0441\u043b\u0438 \u043a\u044d\u0448 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442         print(f\"Cache hit: {response}\")     else:         # \u0415\u0441\u043b\u0438 \u0432 \u043a\u044d\u0448\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e (cache miss)         print(f\"Cache miss: {response}\")          # \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0441 \u0442\u043e\u043f-k \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438         results = vector_store.similarity_search(query, k=k)          # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u044b \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442         context = \"\\n\".join([result.page_content for result in results])          # \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043a\u044d\u0448: \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442         llmcache.store(             prompt=question,             response=context,         )          # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442         print(context) <\/code><\/pre>\n<h4>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 Redis<\/h4>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443 Redis \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 AI \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/redis.io\/blog\/benchmarking-results-for-vector-databases\/\" rel=\"noopener noreferrer nofollow\">\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 GenAI \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439:\u00a0 <a href=\"https:\/\/python.langchain.com\/docs\/integrations\/vectorstores\/redis\/\" rel=\"noopener noreferrer nofollow\">LangChain<\/a>, <a href=\"https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/vector_stores\/RedisIndexDemo\/\" rel=\"noopener noreferrer nofollow\">LlamaIndex<\/a><\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442 <a href=\"https:\/\/redis.io\/langcache\/\" rel=\"noopener noreferrer nofollow\">LangCache<\/a> \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0433\u043e \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <a href=\"https:\/\/github.com\/redis\/redis-vl-python\/blob\/main\/docs\/user_guide\/08_semantic_router.ipynb\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438<\/a> \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1b8\/c0b\/0ef\/1b8c0b0ef9a17dd0f2cbda0c829af9b2.png\" alt=\"\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 Redis \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438\" title=\"\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 Redis \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438\" width=\"1600\" height=\"972\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/1b8\/c0b\/0ef\/1b8c0b0ef9a17dd0f2cbda0c829af9b2.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1b8\/c0b\/0ef\/1b8c0b0ef9a17dd0f2cbda0c829af9b2.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u0430\u044f \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 Redis \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c\u0438<\/figcaption><\/div>\n<\/figure>\n<h4>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430<\/h4>\n<p><strong>\u041f\u043b\u044e\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0421\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a (latency)<\/strong>: \u043f\u0440\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0438\u043b\u0438 \u0441\u0445\u043e\u0436\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0437\u0430\u043d\u043e\u0432\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430\u00a0<\/p>\n<\/li>\n<li>\n<p><strong>\u042d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432<\/strong>: \u0441\u043d\u0438\u0436\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041c\u0438\u043d\u0443\u0441\u044b<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0451\u043c\u0430 \u043a\u044d\u0448\u0430<\/strong>: \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a\u044d\u0448 \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0435<\/strong>: \u043a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0430, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u043e\u0441\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/strong>: \u0435\u0441\u043b\u0438 \u043a\u044d\u0448 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u0442\u0430\u0442\u044c \u043d\u0435\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ul>\n<h2>\u0412\u044b\u0432\u043e\u0434\u044b<\/h2>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/abb\/c66\/5e5\/abbc665e5fc1e4466faa47f2617e235e.png\" width=\"900\" height=\"514\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/abb\/c66\/5e5\/abbc665e5fc1e4466faa47f2617e235e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/abb\/c66\/5e5\/abbc665e5fc1e4466faa47f2617e235e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u2014 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u0448\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u043b\u0430 \u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u043b\u0430 \u043b\u0438\u0448\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0430 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u043a\u044d\u0448\u0430, \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0442\u043e\u0433\u0434\u0430 \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u0443\u043c\u043d\u0435\u0435.<\/p>\n<p><em>\u0410 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u0438\u043b\u0438 \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 RAG \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430\u0445? \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/em><\/p>\n<h2>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h2>\n<ol>\n<li>\n<p><a href=\"https:\/\/huggingface.co\/learn\/cookbook\/en\/semantic_cache_chroma_vector_database\" rel=\"noopener noreferrer nofollow\">\u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0442 HuggingFace \u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 json \u0444\u0430\u0439\u043b\u0430\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=H53L_yHs9jE\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u0434\u0435\u043e \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u0431\u0430\u0437\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 Qdrant<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/redis.io\/docs\/latest\/develop\/ai\/redisvl\/user_guide\/llmcache\/\" rel=\"noopener noreferrer nofollow\">\u0421\u0442\u0430\u0442\u044c\u044f \u043e \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 Redis<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/gptcache.readthedocs.io\/en\/latest\/index.html#\" rel=\"noopener noreferrer nofollow\">GPTCache &#8212; \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u044d\u0448\u0435\u043c<\/a><\/p>\n<\/li>\n<\/ol>\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\/930788\/\"> https:\/\/habr.com\/ru\/articles\/930788\/<\/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<figure class=\"full-width\"><\/figure>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0447\u0430\u0442-\u0431\u043e\u0442\u044b \u0438 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u044b \u0448\u0438\u0440\u043e\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0444\u0435\u0440\u0430\u0445: \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445.\u00a0 \u0414\u043b\u044f \u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 Retrieval-Augmented Generation (RAG), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0431\u043e\u0442\u0430\u043c \u0438 \u0430\u0441\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u0430\u043c \u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e RAG \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043f\u043e\u0432\u044b\u0448\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u043b\u0438\u043a\u0430.<\/p>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0412\u0430\u0434\u0438\u043c, \u044f Data Scientist \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Raft, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c!<\/p>\n<h2>\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 RAG<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0431\u0430\u0437\u043e\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 RAG. \u0412 \u0446\u0435\u043b\u043e\u043c \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 2 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0434\u0435\u043a\u0441\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (Data Indexing)<\/strong>: \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0431\u043e\u0440, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (\u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u043d\u0438\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u043e\u0438\u0441\u043a \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 (Data Retrieval &amp; Generation)<\/strong>: \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0432\u043e\u0434\u0438\u0442 \u0441\u0432\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0435\u0433\u043e \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0438\u0449\u0435\u0442 top-K \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 (chunks) \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.\u00a0 \u0414\u0430\u043b\u0435\u0435, \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, LLM \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\">\n<div><figcaption>\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 RAG <\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b <\/h2>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0439 RAG, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043d\u0430 <u>\u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430<\/u> \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u0430 \u0441\u0447\u0451\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0439 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f, \u043c\u043e\u0434\u0435\u043b\u0435\u0439 reranker-\u043e\u0432 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>\u041d\u043e \u0443 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0435\u0441\u0442\u044c \u043e\u0431\u0449\u0430\u044f \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c: \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u043f\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 <u>\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/u> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0445 \u0438\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0441\u0445\u043e\u0436\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0436\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043a\u043e\u043b\u043e <strong>30%<\/strong> \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043d\u043e\u0432\u043e \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0438\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0438\u00a0 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u0438 \u043a\u0430\u043a \u0435\u0433\u043e \u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c?<\/h2>\n<h3>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448?<\/h3>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u2014 \u044d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u00bb (\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0441\u043c\u044b\u0441\u043b\u0443) \u043f\u043e\u0445\u043e\u0436\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0437\u0430\u043d\u043e\u0432\u043e \u0438\u0441\u043a\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442: \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b\u0441\u044f \u043b\u0438 \u0443\u0436\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441? \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u043c\u0438\u043d\u0443\u044f \u043b\u0438\u0448\u043d\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0412 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043a\u044d\u0448\u0430.\u00a0<\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u00a0\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u00a0\u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u00a0\u2014 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0449\u0435\u043c \u0432 \u043a\u044d\u0448\u0435 \u043e\u0442\u0432\u0435\u0442 \u0438\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u0440\u0435\u0434\u0438 \u0443\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432 \u0438\u00a0 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u044c \u2014 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436, \u0434\u043e\u0441\u0442\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u2014 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u0432\u0435\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u044d\u0448 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b RAG \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u043a\u044d\u0448\u0435\u043c<\/figcaption><\/div>\n<\/figure>\n<h3>\u0412\u0430\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432: \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043c\u0435\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u0438: \u0440\u0435\u0448\u0430\u0435\u043c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c \u00ab\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u044c\u00bb \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e <em>\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e <\/em>\u0438\u043b\u0438<em> \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/em>.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u043e\u0440 \u043f\u043e\u0440\u043e\u0433\u0430 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430: \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u044d\u0448. \u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0440\u043e\u0433 <em>\u043c\u0435\u043d\u044c\u0448\u0435 0.5<\/em><strong>.<\/strong>\u00a0<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 TTL, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043a\u044d\u0448\u0430, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a LRU, FIFO, LFU \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u0445\u0435\u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0439 \u043a\u044d\u0448 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<figure class=\"\"><\/figure>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043d\u0443\u043b\u044f<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043a\u044d\u0448\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 json \u0444\u0430\u0439\u043b\u0435 (\u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0432\u0438\u0434\u0435 <a href=\"https:\/\/github.com\/infoslack\/qdrant-example\/blob\/main\/semantic-cache.ipynb\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439<\/a> \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445).<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u00a0\u043a\u044d\u0448\u0435\u043c\u00a0\u2014 <strong>SemanticCache<\/strong> \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430, \u043f\u043e\u0440\u043e\u0433 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u0435. \u0417\u0434\u0435\u0441\u044c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044e \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u044f FIFO (First-In, First-Out) \u2014 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c\u0438.<\/p>\n<pre><code class=\"python\">class SemanticCache:     def __init__(self, json_file: str = \"cache_file.json\", threshold: float = 0.35,                  max_response: int = 100, eviction_policy: Optional[str] = None, nprobe: int = 8):         \"\"\"         \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u044d\u0448\u0430.          Args:             json_file (str): \u041f\u0443\u0442\u044c \u043a JSON \u0444\u0430\u0439\u043b\u0443 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u044d\u0448\u0430.             threshold (float): \u041f\u043e\u0440\u043e\u0433 \u0415\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043d\u0438\u0436\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438.             max_response (int): \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u044d\u0448\u0435.             eviction_policy (str, optional): \u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, 'FIFO').             nprobe (int): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 Faiss.         \"\"\"         # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c Faiss-\u0438\u043d\u0434\u0435\u043a\u0441 \u0438 \u044d\u043d\u043a\u043e\u0434\u0435\u0440         self.index, self.encoder = init_cache()          self.threshold = threshold         self.json_file = json_file         self.max_response = max_response         self.eviction_policy = eviction_policy         self.nprobe = nprobe          # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043a\u044d\u0448 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439, \u0435\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442         self.cache = retrieve_cache(self.json_file) <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u043c\u0435\u0442\u043e\u0434 <strong>search_in_cache<\/strong>, \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u043a\u044d\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441. \u0412 \u043d\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Faiss \u0438\u0449\u0435\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440. \u0415\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043d\u0435\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430, \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0445\u043e\u0436, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u0432 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u00a0\u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <strong>None<\/strong>.<\/p>\n<pre><code class=\"python\">def _search_in_cache(self, embedding: List[float]) -&gt; Optional[str]:         \"\"\"         \u0418\u0449\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Faiss-\u0438\u043d\u0434\u0435\u043a\u0441\u0435.          Args:             embedding (List[float]): \u0412\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.          Returns:             Optional[str]: \u041d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430, \u043b\u0438\u0431\u043e None, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0442.         \"\"\"         # \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430         self.index.nprobe = self.nprobe          # \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0441\u043e\u0441\u0435\u0434\u0430         D, I = self.index.search(embedding, 1)         distance = D[0][0]         index = I[0][0]          # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0434 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f         if index &gt;= 0 and distance &lt;= self.threshold:             return self.cache['response_text'][index]          # \u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e         return None  <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u044d\u0448 \u043d\u0435 \u0440\u043e\u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <strong>_evict_if_needed, <\/strong>\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 <strong>max_response<\/strong>, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0445 \u043f\u0435\u0440\u0432\u044b\u0445 (\u0441\u0430\u043c\u044b\u0445 \u0441\u0442\u0430\u0440\u044b\u0445) \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<pre><code class=\"python\">def _evict_if_needed(self):         \"\"\"         \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u044d\u0448\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439,         \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438.         \"\"\"         overflow = len(self.cache[\"questions\"]) - self.max_response         if overflow &gt; 0:             # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0437 \u0432\u0441\u0435\u0445 \u0441\u043f\u0438\u0441\u043a\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043a\u044d\u0448 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c             self.cache[\"questions\"] = self.cache[\"questions\"][overflow:]             self.cache[\"embeddings\"] = self.cache[\"embeddings\"][overflow:]             self.cache[\"answers\"] = self.cache[\"answers\"][overflow:]             self.cache[\"response_text\"] = self.cache[\"response_text\"][overflow:] <\/code><\/pre>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 <strong>ask<\/strong> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<ul>\n<li>\n<p> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433;<\/p>\n<\/li>\n<li>\n<p> \u0438\u0449\u0435\u0442 \u0432 \u043a\u044d\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441;<\/p>\n<\/li>\n<li>\n<p> \u0435\u0441\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442, \u0441\u0440\u0430\u0437\u0443 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u2014 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0445 \u0432 \u043a\u044d\u0448 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">def ask(self, question: str, k: int) -&gt; str:         \"\"\"         \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442 \u0438\u0437 \u043a\u044d\u0448\u0430 \u0438\u043b\u0438, \u0435\u0441\u043b\u0438 \u0432 \u043a\u044d\u0448\u0435 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e, \u0438\u0437 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, chromaDB).          Args:             question (str): \u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.             k (int): \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u043f\u0440\u0438 \u043f\u0440\u043e\u043c\u0430\u0445\u0435 \u043a\u044d\u0448\u0430.          Returns:             str: \u0422\u0435\u043a\u0441\u0442 \u043e\u0442\u0432\u0435\u0442\u0430.         \"\"\"         try:             # \u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440             embedding = self.encoder.encode([question])              # \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u0432 \u043a\u044d\u0448\u0435             cached_response = self._search_in_cache(embedding)              if cached_response:                 # \u0415\u0441\u043b\u0438 \u043d\u0430\u0448\u043b\u0438 \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e                 return cached_response              # \u0415\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u043b\u0438 \u2014 \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0430\u0437\u0435             answers = query_database(question, k)              # \u0421\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0435\u0434\u0438\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442             response_text = \"\".join(doc.page_content for doc in answers)              # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441, \u043e\u0442\u0432\u0435\u0442 \u0438 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0432 \u043a\u044d\u0448             self.cache['questions'].append(question)             self.cache['embeddings'].append(embedding[0].tolist())             self.cache['answers'].append(response_text)             self.cache['response_text'].append(response_text)              # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u0432 Faiss-\u0438\u043d\u0434\u0435\u043a\u0441             self.index.add(embedding)              # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0438\u043b\u0441\u044f \u043b\u0438 \u043a\u044d\u0448, \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438             if len(self.cache[\"questions\"]) &gt; self.max_response:<\/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-468541","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468541","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=468541"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/468541\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=468541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=468541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=468541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}