{"id":179,"date":"2026-07-26T21:11:50","date_gmt":"2026-07-26T13:11:50","guid":{"rendered":"https:\/\/fsdata.site\/?p=179"},"modified":"2026-07-26T22:30:17","modified_gmt":"2026-07-26T14:30:17","slug":"ollama-local-knowledge-base-private-qa","status":"publish","type":"post","link":"https:\/\/fsdata.site\/?p=179","title":{"rendered":"Ollama \u672c\u5730\u77e5\u8bc6\u5e93\u642d\u5efa\uff1a30 \u5206\u949f\u641e\u5b9a\u79c1\u57df\u95ee\u7b54"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u8981\u5728\u672c\u5730\u8dd1\uff1f<\/h2>\n<p>\u6570\u636e\u5b89\u5168\u662f\u7b2c\u4e00\u8003\u91cf\u3002\u6bd4\u8d77\u628a\u4f01\u4e1a\u6587\u6863\u4e0a\u4f20\u5230 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/fsdata.site\/ai-agent-function-calling\/\">\u4e91\u7aef AI Agent \u670d\u52a1<\/a>\uff0cOllama \u8ba9\u6240\u6709\u63a8\u7406\u90fd\u5728\u5185\u7f51\u5b8c\u6210\uff0cZero Data Leakage\u3002<\/p>\n<h2>\u5b89\u88c5 Ollama<\/h2>\n<pre><code class=\"language-bash\">curl -fsSL https:\/\/ollama.ai\/install.sh | sh\nollama pull llama3.2<\/code><\/pre>\n<h2>\u52a0\u8f7d\u77e5\u8bc6\u5e93<\/h2>\n<pre><code class=\"language-python\">import ollama\nfrom langchain.document_loaders import DirectoryLoader\nfrom langchain.text_splitter import RecursiveCharacterTextSplitter\n\n# \u52a0\u8f7d\u6587\u6863\nloader = DirectoryLoader('.\/docs\/', glob='**\/*.md')\ndocs = loader.load()\n\n# \u6587\u672c\u5206\u5272\nsplitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)\nsplit = splitter.split_documents(docs)\n\n# \u5d4c\u5165\u5e76\u5b58\u50a8\nfor doc in split:\n    embedding = ollama.embeddings(model='nomic-embed-text', prompt=doc.page_content)<\/code><\/pre>\n<h2>\u6784\u5efa\u95ee\u7b54\u63a5\u53e3<\/h2>\n<pre><code class=\"language-python\">def ask(question):\n    ctx = ollama.search(query=question, top_k=5)\n    response = ollama.chat(\n        model='llama3.2',\n        messages=[{'role': 'user', 'content': f'{ctx} Q: {question}'}]\n    )\n    return response['message']['content']<\/code><\/pre>\n<p>\u8fd9\u4e2a\u65b9\u6848\u7684\u6838\u5fc3\u601d\u60f3\u662f RAG\uff08Retrieval-Augmented Generation\uff09\uff0c\u4e0e <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/fsdata.site\/kubernetes-pod-troubleshooting\/\">Kubernetes Pod \u6545\u969c\u6392\u67e5<\/a>\u7684\u601d\u8def\u4e00\u6837\u2014\u2014\u5148\u7528\u68c0\u7d22\u5b9a\u4f4d\u8d44\u6e90\uff0c\u518d\u9488\u5bf9\u6027\u5904\u7406\u3002<\/p>\n<h2>\u5173\u952e\u8981\u70b9<\/h2>\n<ol>\n<li><strong>\u6a21\u578b\u9009\u62e9<\/strong>\uff1a7B \u53c2\u6570\u591f\u7528\uff0c70B \u7cbe\u5ea6\u66f4\u9ad8\u4f46\u6162 3 \u500d<\/li>\n<li><strong>\u6587\u6863\u5207\u5272<\/strong>\uff1achunk_size 500-800 \u6548\u679c\u6700\u597d<\/li>\n<li><strong>\u5d4c\u5165\u6a21\u578b<\/strong>\uff1anomic-embed-text \u514d\u8d39\u4e14\u591f\u7528<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>30 \u5206\u949f\u7528 Ollama \u642d\u5efa\u672c\u5730\u77e5\u8bc6\u5e93\u95ee\u7b54\u7cfb\u7edf\uff0c\u4e0d\u4f9d\u8d56\u4efb\u4f55\u4e91\u670d\u52a1\uff0c\u652f\u6301 PDF\/Markdown \u5bfc\u5165\uff0cZero Data Leakage\u3002<\/p>\n","protected":false},"author":2,"featured_media":206,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[34,57,59,62,63],"class_list":["post-179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-app","tag-ollama","tag-57","tag-ai","tag-62","tag-63"],"_links":{"self":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=179"}],"version-history":[{"count":4,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/179\/revisions\/242"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/media\/206"}],"wp:attachment":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}