Building a Local AI Knowledge Base: Tool Selection, Setup, and Security Maintenance
This guide walks through building a local knowledge base that AI tools can read and query, covering tool selection, directory setup, workspace binding, document conversion, retrieval mechanisms, and security practices like backups and credential rotation. It includes verification steps, troubleshooting tables, and sample commands to help you avoid common pitfalls such as unreliable ignore rules and fabricated AI answers.
1. Tool Selection and Cost: Verify Before You Build
You need two kinds of tools for this setup. The first is a local note-taking app that stores and organizes your materials. The second is an AI tool that reads those materials and answers questions. When evaluating tools, check three things: whether you can designate a specific local directory as the workspace, whether file contents get uploaded to the cloud, and whether the free-tier rules are clearly documented.
| Component | Recommended Choice | What to Verify During Selection |
|---|---|---|
| Note-taking app | Obsidian, which stores notes as plain .md files in local folders |
The official sync service is paid; whether you need sync depends on the official site |
| AI tool | Workspace-capable AI coding tools such as VS Code or Cursor, or other clients that support local directories | Whether read scope can be restricted, whether ignore rules can be set, whether index data is uploaded |
| LLM | Lightweight models (names containing mini, flash, or lite) | Billing terms, context length, whether the model may be retired |
| Local model (alternative) | Run open-source models with Ollama; inference happens entirely on your machine | Requires sufficient RAM and VRAM; answer quality is typically below cloud flagship models |
Lightweight models work well for everyday summarization and simple Q&A. For full-document analysis, multi-step reasoning, or conclusions that require synthesizing multiple sources, lightweight models tend to miss details. For such tasks, use the lightweight model for a first pass, then have a stronger model or a human review the key conclusions.
This article does not list billing rates or quota refresh times, because those figures change across platforms and over time. Rely on the following checks instead:
| Item to Check | Where to Look | Why It Matters |
|---|---|---|
| Billing model (per token, per request, or per credit) | The platform’s pricing page | The same model can vary widely in cost depending on the billing unit |
| Free quota and validity period | Account or quota page | Quotas may be granted daily, monthly, or only once |
| Check-in rules and refresh times | Promotion pages or help center | Follow the platform’s stated rules rather than assumptions |
| Model updates and deprecations | Platform changelog | Avoid workflows that depend on retired models |
| Whether data is uploaded to the cloud | Privacy policy and tool settings | When using cloud models, file contents attached to prompts are sent to the provider |
2. Environment Setup: Create a Directory and Bind the Workspace
1. Create a dedicated directory
Do not set your entire home directory or desktop as the workspace. Instead, create a dedicated knowledge base root directory, kb-root:
kb-root/├── 00-inbox/ Unprocessed raw materials├── 01-tech/ Technical documentation notes├── 02-reading/ Reading notes├── 03-projects/ Project retrospectives└── 99-archive/ Archived or superseded notes
Keep sensitive materials (passwords, keys, original contracts, etc.) outside the workspace, for example in ~/private/. That way the AI client simply cannot see them. If they must live inside kb-root, exclude them through the client’s ignore settings.
2. Review ignore rules carefully
Many people assume .gitignore prevents AI tools from reading files. This is unreliable: .gitignore only governs Git version control and does not guarantee the AI client will honor it. Consult your tool’s documentation and add secrets/, .env, and *.key to its own ignore settings, one by one.
After configuration, run a test: place a test.key file with unique content in the workspace, then ask the AI for its contents. If the AI can answer, the ignore rules are not working and you need to recheck the settings.
3. Bind the workspace
In the AI client’s settings, look for options like “Workspace,” “Project Directory,” or “Open Folder,” then select kb-root. Where these options appear varies by version—trust the current UI.
After binding, check file access permissions for your operating system:
| OS | Where to Check | Common Failure Symptoms |
|---|---|---|
| macOS | System Settings > Privacy & Security > Files and Folders | The app cannot access the directory; read operations fail |
| Windows | Virus & threat protection > Ransomware protection > Controlled folder access | Read/write operations are blocked |
| Linux | Check directory permissions with ls -l; with containers, verify mount paths |
Permission denied errors, or files not found inside the container |
Use UTF-8 encoding consistently. Keep individual Markdown files within a few dozen KB; split larger files by second-level headings. This is a practical recommendation from this article, not a hard tool limit—defer to the tool’s documentation for actual constraints.
4. Verify the AI can read files
Before importing real materials, run a verification:
- Create
verify-test.mdin00-inbox/containing a unique passphrase, such as “Verification passphrase: Heron-4417.” - Ask the AI: “What is the verification passphrase in verify-test.md in the workspace? Provide the file path.”
- If the answer contains both the passphrase and the file path, reading works correctly.
If verification fails, troubleshoot using the table below:
| Symptom | Likely Cause | Fix |
|---|---|---|
| “File not found” | Workspace bound to the wrong directory | Recheck the workspace path |
| Answers correctly but gives no path | The tool may only read the currently open tab | Check context or indexing settings |
| Permission error | The OS has not granted directory access | Grant access in the system privacy settings |
| Answer contradicts the file | The model is fabricating content | Require the AI to cite the file path; discard any answer without one |
| New files are never found | The file is excluded by ignore rules, or the index has not updated | Check ignore rules and file extensions; wait for indexing to finish, then retry |
3. Document Conversion and Retrieval Workflow
1. Back up before converting
Conversion modifies file contents, so protect the originals first. Copy raw materials into a separate raw-backup/ directory and make it read-only. Then test the pipeline on two or three files before batch processing.
Always write converted output to a new path. If OCR or format conversion fails, the original file stays intact.
Identify the material type before choosing a tool:
- Text-based PDFs: extract text with PyMuPDF or pdfplumber.
- Scanned PDFs: add a text layer with OCRmyPDF first, then extract. OCR requires the matching language pack, such as
chi_simfor Simplified Chinese. - Word documents: convert with Pandoc and extract images to a separate directory.
- Web pages and other formats: try Microsoft’s open-source MarkItDown tool.
Sample commands—install dependencies and confirm versions first:
# Convert Word to Markdown, saving images to the assets directorypandoc project-plan.docx -t gfm --extract-media=./assets -o 03-projects/project-plan.md# Add a text layer to a scanned PDF (install the Tesseract Chinese language pack first)ocrmypdf --language chi_sim+eng scanned.pdf searchable.pdf# Convert PDF to Markdownpip install markitdownmarkitdown reading-notes.pdf > 02-reading/reading-notes.md
Manual spot checks after conversion are mandatory. Tables, formulas, and code blocks are frequently misaligned—especially in multi-column PDFs. When checking, compare numbers and proper nouns paragraph by paragraph against the source.
You can have the AI help clean up formatting, but restrict it from rewriting content. A recommended prompt:
Please reformat the following text as structured Markdown. Preserve all original numbers and proper nouns; do not add anything not present in the source. Use Markdown table syntax for tables. Mark anything uncertain with [TO VERIFY]. Text: …
For example, if the source reads “Sales grew 18% in 2025, mainly driven by the East China market,” and the output becomes “Sales grew 18% in 2025, versus an industry average of 12%, mainly driven by the East China market,” the AI has added a figure not in the original. Reject such output—ask it to redo the formatting or fix it manually.
Use a “date-topic-source” naming convention, for example 2026-11-25-microservices-official-docs.md. When files from the same day and topic collide, append a sequence number like -02. Add a metadata block at the top of each file for easier retrieval and filtering later:
---title: Introduction to Microservicessource: Official documentation link or book titledate: 2026-11-25sensitivity: public # public / internal / secret---
2. Understand the three retrieval mechanisms
People often call “workspace context” RAG, but that is inaccurate. There are three common retrieval approaches:
| Approach | How It Works | Best For | Main Limitations |
|---|---|---|---|
| Full-context injection | Puts entire files into the prompt | Few files, small total volume | Limited by the context window; costs grow with file count |
| Keyword search | Matches files by word, similar to grep | Finding names, IDs, proper nouns | Synonyms or rephrased queries may fail |
| Vector retrieval (RAG) | Splits text into chunks, generates an embedding per chunk; at query time, the semantically closest chunks are passed to the model | Many documents, varied question phrasing | Poor chunking breaks context; index building is required and index updates may lag |
3. The retrieval workflow
Validate the following steps in order. Confirm each step before moving on:
- Build the index: have the client index the workspace and wait for completion.
- Chunking: confirm how text is split. When chunking by heading, each chunk should retain the file path and heading.
- Recall: ask a question with a known answer and check whether the retrieved content is relevant.
- Cited paths: answers must include the file path and title. Discard any answer without one.
- Failure triage: if content cannot be found, check ignore rules, file extensions, and index timing in that order. If it still fails, cross-check with keyword search.
Prepare five test questions with known answers and record pass/fail results for each retrieval run. Re-run the same test set after every model change, tool upgrade, or bulk import of new materials.
4. Security and Maintenance: Backups, Rotation, and Recovery
1. Backup and version control
Manage kb-root with Git to record every change and roll back to earlier versions when something goes wrong:
cd kb-rootgit initgit add 00-inbox 01-tech 02-reading 03-projects 99-archivegit commit -m "Initialize knowledge base"
Before committing, run git status to confirm no sensitive files are included. Keep the repository local only, or push it to a private remote that you control. Never push the repository to a public platform.
Git history is not a substitute for backups. When the repository and original files share the same disk, a disk failure destroys both. Once a week, copy the entire kb-root to a separate disk or encrypted cloud storage, and spot-check that three random files open correctly.
2. Credential rotation
If sensitive
