-
-
Notifications
You must be signed in to change notification settings - Fork 97
Knowledge System
The AI Runner knowledge system provides long-term memory capabilities for the LLM, allowing it to remember facts about the user, conversations, and context across sessions.
AI Runner uses a markdown-based knowledge system with daily files stored in a structured format. Facts are organized by section and indexed for RAG (Retrieval-Augmented Generation) semantic search.
-
Daily Files: Facts stored in dated markdown files (
YYYY-MM-DD.md) - Section Organization: Facts organized by category (Identity, Work, Interests, etc.)
- RAG Integration: Vector-based retrieval using embeddings for efficient fact recall
- Human-Readable: Easy to view, edit, and backup using any text editor
- Automatic Indexing: All knowledge files indexed for semantic search
Knowledge is stored as markdown files in: ``` ~/.local/share/airunner/text/knowledge/ ├── 2025-01-15.md ├── 2025-01-16.md ├── 2025-01-17.md └── ... ```
Each daily knowledge file follows this template:
```markdown
User's name is Joe.
User is a software developer.
User works on AI Runner project.
User enjoys programming and AI research.
User prefers dark mode interfaces.
User wants to create accessible AI tools.
```
Facts are organized into these sections:
| Section | Description |
|---|---|
| Identity | Name, age, gender, basic personal info |
| Work & Projects | Job, company, current projects |
| Interests & Hobbies | Hobbies, topics of interest |
| Preferences | Likes, dislikes, habits |
| Health & Wellness | Health info (if shared) |
| Relationships | Family, friends |
| Goals | What user wants to achieve |
| Notes | Miscellaneous information |
Facts are added through conversation or the LLM tools:
```python
```
Facts are retrieved via RAG semantic search:
```python from airunner.components.knowledge.knowledge_base import get_knowledge_base
kb = get_knowledge_base()
context = kb.get_context("What programming languages does the user like?")
recent = kb.get_recent_facts(days=7)
matches = kb.search("Python") ```
The knowledge system implements a tiered memory approach:
``` ┌─────────────────────────────────────────────────┐ │ Tier 1: Working Memory (RAM) │ │ - Current conversation context │ │ - Recently accessed facts (cached) │ └─────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────┐ │ Tier 2: Daily Knowledge (Markdown) │ │ - Facts stored in daily .md files │ │ - Organized by section │ │ - Human-readable and editable │ └─────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────┐ │ Tier 3: RAG Semantic Search (Vector Store) │ │ - All knowledge files indexed │ │ - Semantic similarity search │ │ - Retrieved based on query relevance │ └─────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────┐ │ Tier 4: Document Library (RAG) │ │ - Ebooks, PDFs, markdown docs │ │ - Broad document search │ │ - See: RAG Search documentation │ └─────────────────────────────────────────────────┘ ```
Open any daily knowledge file with a text editor:
```bash
cat ~/.local/share/airunner/text/knowledge/$(date +%Y-%m-%d).md
ls ~/.local/share/airunner/text/knowledge/
code ~/.local/share/airunner/text/knowledge/ ```
Simply edit the markdown files directly:
- Open the knowledge directory
- Find the relevant date file
- Edit the text under the appropriate section
- Save the file
Changes are automatically picked up on next RAG index refresh.
The knowledge directory can be easily backed up:
```bash
cp -r ~/.local/share/airunner/text/knowledge/ ~/knowledge-backup/
cp -r ~/knowledge-backup/* ~/.local/share/airunner/text/knowledge/ ```
The LLM has access to knowledge tools for managing facts:
Records a new fact to the knowledge base.
Parameters:
- `text` (str): The fact to record
- `section` (str): Which section to add it to (Identity, Work & Projects, etc.)
Searches the knowledge base for relevant facts.
Parameters:
- `query` (str): Search query
Gets relevant user context for the current conversation.
Knowledge system can be configured via settings:
```python
llm_settings.auto_extract_knowledge = True
knowledge_settings.max_context_facts = 20 ```
- Check if knowledge files exist in `~/.local/share/airunner/text/knowledge/`
- Verify the LLM has knowledge tools available
- Check logs for any errors during tool execution
- Ensure RAG indexing is complete
- Consider reducing the number of historical knowledge files
- Check that embeddings model is loaded
- RAG Search - Document-based knowledge retrieval
- Architecture - System design overview
- Tools - Available LLM tools