{"id":719,"date":"2025-12-09T19:34:13","date_gmt":"2025-12-09T11:34:13","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=719"},"modified":"2025-12-09T19:34:13","modified_gmt":"2025-12-09T11:34:13","slug":"%e4%bd%bf%e7%94%a8deepseek%e6%90%ad%e5%bb%ba%e4%b8%aa%e4%ba%ba%e7%9f%a5%e8%af%86%e5%ba%93%e5%9c%a8%e7%ac%94%e8%ae%b0%e6%9c%ac%e7%94%b5%e8%84%91%e4%b8%8a","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/09\/%e4%bd%bf%e7%94%a8deepseek%e6%90%ad%e5%bb%ba%e4%b8%aa%e4%ba%ba%e7%9f%a5%e8%af%86%e5%ba%93%e5%9c%a8%e7%ac%94%e8%ae%b0%e6%9c%ac%e7%94%b5%e8%84%91%e4%b8%8a\/","title":{"rendered":"\u4f7f\u7528DeepSeek\u642d\u5efa\u4e2a\u4eba\u77e5\u8bc6\u5e93(\u5728\u7b14\u8bb0\u672c\u7535\u8111\u4e0a)"},"content":{"rendered":"\n<p>\u4e0b\u9762\u6211\u7ed9\u4f60\u6574\u7406\u4e00\u7bc7<strong>\u4f7f\u7528 DeepSeek \u5728\u7b14\u8bb0\u672c\u7535\u8111\u4e0a\u642d\u5efa\u4e2a\u4eba\u77e5\u8bc6\u5e93\u7684\u8be6\u7ec6\u5b9e\u6218\u6307\u5357<\/strong>\uff0c\u6db5\u76d6\u73af\u5883\u51c6\u5907\u3001\u5b89\u88c5\u90e8\u7f72\u3001\u6587\u6863\u5411\u91cf\u5316\u3001\u68c0\u7d22\u6d4b\u8bd5\u548c\u5e38\u89c1\u95ee\u9898\uff0c\u9002\u5408\u5355\u673a\u5b9e\u9a8c\u548c\u5b66\u4e60\u4f7f\u7528\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e00\u3001DeepSeek \u7b80\u4ecb<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DeepSeek<\/strong> \u662f\u4e00\u4e2a\u8f7b\u91cf\u5316\u7684\u5411\u91cf\u641c\u7d22\/\u8bed\u4e49\u641c\u7d22\u5de5\u5177\uff0c\u53ef\u4ee5\u628a\u6587\u6863\u3001\u7b14\u8bb0\u3001PDF\u3001Markdown \u7b49\u5185\u5bb9\u8f6c\u6210\u5411\u91cf\u5b58\u50a8\uff0c\u65b9\u4fbf\u8bed\u4e49\u68c0\u7d22\u3002<\/li>\n\n\n\n<li>\u7279\u70b9\uff1a\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u591a\u79cd\u6587\u6863\u683c\u5f0f<\/li>\n\n\n\n<li>\u517c\u5bb9\u672c\u5730 Python \u73af\u5883<\/li>\n\n\n\n<li>\u53ef\u4e0e LLM\uff08\u5982 Ollama\u3001OpenAI \u6a21\u578b\uff09\u7ed3\u5408\u6784\u5efa\u4e2a\u4eba\u77e5\u8bc6\u95ee\u7b54\u7cfb\u7edf<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5728\u7b14\u8bb0\u672c\u7535\u8111\u4e0a\u8fd0\u884c\u65f6\uff0c\u63a8\u8350\u5c0f\u578b embedding \u6a21\u578b\u6216 CPU\/\u5c0f GPU \u7248\u672c\uff0c\u4ee5\u4fdd\u8bc1\u6027\u80fd\u53ef\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u73af\u5883\u51c6\u5907<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7cfb\u7edf\u73af\u5883<\/strong>\n<ul class=\"wp-block-list\">\n<li>Windows \/ macOS \/ Linux \u5747\u53ef<\/li>\n\n\n\n<li>Python >= 3.8\uff08\u63a8\u8350 3.10\/3.12\uff09<\/li>\n\n\n\n<li>pip \u6216 conda \u5305\u7ba1\u7406\u5de5\u5177<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u786c\u4ef6\u5efa\u8bae<\/strong>\n<ul class=\"wp-block-list\">\n<li>CPU\uff1a4 \u6838\u4ee5\u4e0a<\/li>\n\n\n\n<li>\u5185\u5b58\uff1a16GB \u4ee5\u4e0a\uff08\u89c6\u6587\u6863\u91cf\u800c\u5b9a\uff09<\/li>\n\n\n\n<li>GPU\uff1a\u53ef\u9009\uff0c\u5982\u679c\u4f7f\u7528\u5927\u578b embedding \u6a21\u578b\u4f1a\u52a0\u901f<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Python \u865a\u62df\u73af\u5883<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# \u4f7f\u7528 venv\npython -m venv deepseek_env\nsource deepseek_env\/bin\/activate    # Linux\/macOS\ndeepseek_env\\Scripts\\activate       # Windows\n\n# \u66f4\u65b0 pip\npip install --upgrade pip\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e09\u3001\u5b89\u88c5 DeepSeek<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5b89\u88c5 DeepSeek \u5b98\u65b9\u5305\uff08\u5047\u8bbe\u5df2\u7ecf\u6709 pip \u7f51\u7edc\u73af\u5883\uff09<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npip install deepseek\n\n<\/pre><\/div>\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npython -c &quot;import deepseek; print(deepseek.__version__)&quot;\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u56db\u3001\u6587\u6863\u51c6\u5907\u4e0e\u5411\u91cf\u5316<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6574\u7406\u4e2a\u4eba\u6587\u6863<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301 PDF\u3001TXT\u3001Markdown\u3001Word \u7b49\u683c\u5f0f<\/li>\n\n\n\n<li>\u5efa\u8bae\u5c06\u6587\u6863\u653e\u5728\u7edf\u4e00\u76ee\u5f55\uff0c\u4f8b\u5982 <code>~\/my_knowledge<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5411\u91cf\u5316\u6587\u6863<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom deepseek import DeepSeek\n\n# \u521d\u59cb\u5316 DeepSeek\uff08\u672c\u5730\u5b58\u50a8\uff09\nds = DeepSeek(index_path=&quot;.\/my_knowledge_index&quot;)\n\n# \u6dfb\u52a0\u6587\u6863\nds.add_documents_from_folder(&quot;.\/my_knowledge&quot;)  # \u81ea\u52a8\u626b\u63cf\u76ee\u5f55\u4e0b\u6587\u6863\n\n# \u6784\u5efa\u5411\u91cf\u7d22\u5f15\nds.build_index()\n\n<\/pre><\/div>\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u68c0\u67e5\u7d22\u5f15<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nprint(f&quot;Total documents indexed: {len(ds.documents)}&quot;)\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e94\u3001\u8bed\u4e49\u68c0\u7d22\u6d4b\u8bd5<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7b80\u5355\u67e5\u8be2<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nquery = &quot;\u89e3\u91ca\u6df1\u5ea6\u5b66\u4e60\u4e2d\u7684\u68af\u5ea6\u4e0b\u964d&quot;\nresults = ds.search(query, top_k=5)\n\nfor i, res in enumerate(results):\n    print(f&quot;{i+1}. {res&#x5B;&#039;text&#039;]&#x5B;:200]}...&quot;)  # \u8f93\u51fa\u524d 200 \u4e2a\u5b57\u7b26\n\n<\/pre><\/div>\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u4e0e LLM \u7ed3\u5408<\/strong><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom deepseek import DeepSeek\nfrom ollama import Ollama  # \u5047\u8bbe\u5df2\u7ecf\u5b89\u88c5 Ollama\n\nds = DeepSeek(index_path=&quot;.\/my_knowledge_index&quot;)\nllm = Ollama(base_url=&quot;http:\/\/localhost:11434&quot;, model=&quot;llama-2-7b&quot;)\n\nquery = &quot;\u4ec0\u4e48\u662f\u5f3a\u5316\u5b66\u4e60\uff1f&quot;\ndocs = ds.search(query, top_k=3)\ncontext = &quot;\\n&quot;.join(&#x5B;d&#x5B;&quot;text&quot;] for d in docs])\n\nresponse = llm.prompt(f&quot;\u6839\u636e\u4ee5\u4e0b\u5185\u5bb9\u56de\u7b54\u95ee\u9898\uff1a\\n{context}\\n\u95ee\u9898\uff1a{query}&quot;)\nprint(response)\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u516d\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u95ee\u9898<\/th><th>\u89e3\u51b3\u65b9\u6848<\/th><\/tr><\/thead><tbody><tr><td>\u6587\u6863\u8def\u5f84\u5305\u542b\u4e2d\u6587\u6216\u7a7a\u683c<\/td><td>\u5efa\u8bae\u8def\u5f84 UTF-8 \u7f16\u7801\uff0c\u907f\u514d\u7279\u6b8a\u5b57\u7b26<\/td><\/tr><tr><td>CPU \u8fd0\u884c\u592a\u6162<\/td><td>\u4f7f\u7528\u5c0f\u578b embedding \u6a21\u578b\u6216\u51cf\u5c11\u6587\u6863\u91cf\uff0c\u652f\u6301 batch \u5411\u91cf\u5316<\/td><\/tr><tr><td>PDF \u89e3\u6790\u5931\u8d25<\/td><td>\u786e\u8ba4 PDF \u53ef\u8bfb\u6216\u4f7f\u7528 OCR \u9884\u5904\u7406<\/td><\/tr><tr><td>\u67e5\u8be2\u7ed3\u679c\u4e0d\u51c6<\/td><td>\u8c03\u6574 embedding \u6a21\u578b\u3001top_k \u6216\u4f7f\u7528\u66f4\u9002\u5408\u4e2d\u6587\u7684\u6a21\u578b<\/td><\/tr><tr><td>LLM \u54cd\u5e94\u6162<\/td><td>\u9650\u5236\u4e0a\u4e0b\u6587\u957f\u5ea6\uff0c\u6216\u5c06\u68c0\u7d22\u5185\u5bb9\u6458\u8981\u540e\u518d\u9001\u5165\u6a21\u578b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e03\u3001\u5b9e\u6218\u7ecf\u9a8c\u603b\u7ed3<\/h1>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5148\u5c0f\u89c4\u6a21\u6d4b\u8bd5<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u5efa\u8bae\u5148\u7528\u51e0\u4efd\u6587\u6863\u6d4b\u8bd5\u7d22\u5f15\u548c\u68c0\u7d22\u6d41\u7a0b\uff0c\u786e\u8ba4\u53ef\u7528\u540e\u518d\u5bfc\u5165\u5927\u91cf\u6587\u6863\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4f18\u5316\u7d22\u5f15<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u6279\u91cf\u5411\u91cf\u5316\u3001\u542f\u7528\u7f13\u5b58\u3001\u5408\u7406\u8bbe\u7f6e top_k \u53ef\u4ee5\u660e\u663e\u63d0\u9ad8\u67e5\u8be2\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u4e2d\u6587\u5904\u7406<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6587\u6863\u662f\u4e2d\u6587\uff0c\u9009\u7528\u4e2d\u6587 embedding \u6a21\u578b\uff08\u5982 sentence-transformers \u4e2d\u6587\u6a21\u578b\uff09\u6548\u679c\u66f4\u597d\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u7ed3\u5408 LLM<\/strong>\n<ul class=\"wp-block-list\">\n<li>\u5c06\u68c0\u7d22\u7ed3\u679c\u4f5c\u4e3a\u4e0a\u4e0b\u6587\u8f93\u5165 LLM\uff0c\u53ef\u5b9e\u73b0\u66f4\u51c6\u786e\u7684\u95ee\u7b54\u6216\u603b\u7ed3\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u516b\u3001\u603b\u7ed3<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DeepSeek + \u672c\u5730 LLM<\/strong> \u662f\u5728\u7b14\u8bb0\u672c\u4e0a\u642d\u5efa\u4e2a\u4eba\u77e5\u8bc6\u5e93\u7684\u7406\u60f3\u7ec4\u5408\u3002<\/li>\n\n\n\n<li>\u6d41\u7a0b\uff1a\u6574\u7406\u6587\u6863 \u2192 \u6dfb\u52a0\u5230 DeepSeek \u2192 \u6784\u5efa\u7d22\u5f15 \u2192 \u68c0\u7d22\u67e5\u8be2 \u2192 \u53ef\u9009\u7ed3\u5408 LLM \u751f\u6210\u7b54\u6848\u3002<\/li>\n\n\n\n<li>\u907f\u514d\u8def\u5f84\u4e2d\u6587\/\u7279\u6b8a\u5b57\u7b26\u3001\u63a7\u5236\u7d22\u5f15\u89c4\u6a21\u3001\u4f7f\u7528\u5408\u9002 embedding \u6a21\u578b\u662f\u5173\u952e\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u6211\u7ed9\u4f60\u6574\u7406\u4e00\u7bc7\u4f7f\u7528 DeepSeek \u5728\u7b14\u8bb0\u672c\u7535\u8111\u4e0a\u642d\u5efa\u4e2a\u4eba\u77e5\u8bc6\u5e93\u7684\u8be6\u7ec6\u5b9e\u6218&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/09\/%e4%bd%bf%e7%94%a8deepseek%e6%90%ad%e5%bb%ba%e4%b8%aa%e4%ba%ba%e7%9f%a5%e8%af%86%e5%ba%93%e5%9c%a8%e7%ac%94%e8%ae%b0%e6%9c%ac%e7%94%b5%e8%84%91%e4%b8%8a\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-719","post","type-post","status-publish","format-standard","hentry","category-2"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=719"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/719\/revisions"}],"predecessor-version":[{"id":720,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/719\/revisions\/720"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}