Skip to main content

zk-chat is a command-line chat tool for your zettelkasten

Project description

💬 Chat With Your Zettelkasten

This is a simple tool that lets you chat with an "AI" that has access to the documents in your Zettelkasten. It will index your markdown documents, and in your chat session it may choose to query your content, retrieve excerpts, read entire documents, and generate responses based on the content in your Zettelkasten.

For "AI" it communicates with either a local running instance of Ollama or OpenAI's API. By default, Ollama is used and must be installed and running for zkchat to function, but you can also configure it to use OpenAI with the --gateway openai option.

✨ Features

  • Command-line interface for quick access
  • (Experimental) Graphical user interface for a more user-friendly experience
  • RAG queries across your document base
  • Interactive chat with context from your Zettelkasten
  • Configurable LLM model selection
  • Optional visual analysis capability for images in your Zettelkasten
  • Easy Zettelkasten folder configuration

🛠️ Tools

The chat interface provides access to several tools that enhance its capabilities:

  • Document Management Tools

    • Find Documents: Locates relevant documents in your Zettelkasten based on your query
    • Find Excerpts: Retrieves specific passages from your documents that match your search criteria
    • List Documents: Displays all documents in your Zettelkasten for easier navigation
    • Read Document: Accesses the full content of a specific document in your Zettelkasten
    • Write Document: Creates or updates documents in your Zettelkasten (requires --unsafe flag)
    • Rename Document: Changes the name of an existing document in your Zettelkasten (requires --unsafe flag)
    • Delete Document: Permanently removes a document from your Zettelkasten (requires --unsafe flag)
  • Visual Analysis Tools

    • Analyze Image: Examines and describes the content of images in your Zettelkasten (requires a visual model to be configured)
  • Navigation Tools

    • Resolve WikiLink: Converts wikilinks (e.g., [[Document Title]]) to relative file paths for navigation between documents
  • Smart Memory Tools

    • Store Information: Saves important facts and context from conversations for future reference
    • Retrieve Information: Recalls previously stored information to provide more personalized responses
  • Git Integration Tools

    • View Uncommitted Changes: Shows pending changes in your Zettelkasten vault
    • Commit Changes: Commits changes with AI-generated commit messages
  • Available Tool Plugins

    • zk-rag-wikipedia: A plugin for looking up information on Wikipedia and creating documents from the results
    • zk-rag-image-generator: A plugin for generating images using Stable Diffusion 3.5 Medium

🔌 Plugin Development

Zk-Chat supports a rich plugin architecture that allows developers to extend the chat agent with custom tools. See PLUGINS.md for a comprehensive guide on developing plugins that integrate with the zk-chat runtime environment.

🔧 Requirements

If using the default Ollama gateway, you must have ollama installed and running.

If using the OpenAI gateway, you must have the OPENAI_API_KEY environment variable set with your OpenAI API key.

For visual analysis capabilities, you need a model that supports image analysis:

  • For Ollama: models like llava, bakllava, or other multimodal models
  • For OpenAI: models like gpt-4-vision or other vision-capable models

You must have a local knowledgebase / zettelkasten with content in markdown format. I use Obsidian, because I favour working locally, and I favour using the markdown format for notes - because everything's local, and in plain text, I can simply point this tool at a Vault folder.

💻 Workstation setup

Right now, while this tool should run on Windows, but we've only written instructions for Mac.

Using pipx (recommended)

pipx is a tool that allows you to install and run Python applications in isolated environments. It's ideal for end-user applications like zk-chat, as it keeps the application and its dependencies isolated from your system Python and other applications.

Installing pipx:

# On macOS
brew install pipx
pipx ensurepath

# On Linux
python3 -m pip install --user pipx
python3 -m pipx ensurepath

Installing zk-chat with pipx:

pipx install zk-chat

Upgrading zk-chat with pipx:

pipx upgrade zk-chat

Installing plugins with pipx inject:

# Install the Wikipedia plugin
pipx inject zk-chat zk-rag-wikipedia

The benefit of using pipx is that it creates isolated environments for each application, avoiding dependency conflicts while still making the commands globally available.

Alternative: Using a virtual environment

If you prefer more control over your Python environment, you can set up a local virtual environment:

Setting up a local environment, and activating it:

cd $HOME
python3 -mvenv .venv
source .venv/bin/activate

Installing the zk-chat module from PyPi:

pip install zk-chat

Optionally install tool plugins from PyPi:

pip install zk-rag-wikipedia

Setting up Ollama and installing a local model (if using the Ollama gateway):

brew install ollama
ollama pull qwen2.5:14b

Setting up OpenAI (if using the OpenAI gateway):

export OPENAI_API_KEY=your_api_key_here

🚀 Usage

📟 Command-line Interface

Run zkchat --vault /path/to/vault to start the command-line interface for the first time on a new vault.

If zk-chat hasn't been used with the vault before, it will prompt you for:

  1. A chat model (using the default Ollama gateway)
  2. Whether you want to select a visual analysis model (optional)

It will then perform a full index of your vault before starting the chat.

Subsequently running zkchat on its own will launch it on the last opened vault, with the last selected models.

If you want to allow the AI to make changes to your Zettelkasten, you must use the --unsafe flag. We highly recommend using git for version control if you enable this option.

Specifying --git will initialize a new git repository for your vault if one doesn't already exist.

Command-line options:

  • --vault PATH: Specify the path to your Zettelkasten vault (required if no bookmarks are set)
  • --bookmark NAME: Use a bookmarked vault path instead of specifying the path directly
  • --add-bookmark NAME PATH: Add a new bookmark for a vault path
  • --remove-bookmark NAME: Remove a bookmarked vault path
  • --list-bookmarks: List all bookmarked vault paths
  • --gateway {ollama,openai}: Set the model gateway to use (ollama or openai). OpenAI requires OPENAI_API_KEY environment variable
  • --model [model_name]: Change the LLM model to use for chat
    • With model name: zkchat --vault /path/to/vault --model llama2 - configure to use specified model
    • Without model name: zkchat --vault /path/to/vault --model - interactively select from available models
  • --visual-model [model_name]: Change the LLM model to use for visual analysis (optional)
    • With model name: zkchat --vault /path/to/vault --visual-model llava - configure to use specified model for visual analysis
    • Without model name: zkchat --vault /path/to/vault --visual-model - interactively select from available models
    • To disable visual analysis: zkchat --vault /path/to/vault --visual-model none
  • --reindex: Reindex the Zettelkasten vault, will attempt to do so incrementally
  • --full: Force full reindex (only used with --reindex)
  • --unsafe: Enable operations that can write to your Zettelkasten. This flag is required for using tools that modify your Zettelkasten content, such as the Write Document tool. Use with caution as it allows the AI to make changes to your files.
  • --reset-memory: Clear the smart memory storage
  • --git: Enable Git integration for version control of your Zettelkasten vault
  • --store-prompt: Store the system prompt to the vault (default behavior) so that it can be customized

Note on Models

For local models on Ollama, you're going to need to choose a model that fits in your available RAM (on MacOS) or in the VRAM on your GPU. The actual RAM used will vary based on many factors.

Our recommendation is a 14B to 28B parameter model like qwen2.5:14b or phi4:14b or even qwq:32b (if you don't run a lot of other programs at the same time) on a Macbook Pro M1 or later with 36GB of RAM or more.

The lower the number of parameters, the faster the model will be, but the less capable it will be. The higher the number of parameters, the slower the model will be, but the more capable it will be.

In general, newer models are more capable and more accurate. Certain models will be tuned for specific use cases. Read up on the models to understand what they're good at.

You will need to experiment to find the right balance for your system and use cases.

🖼️ Visual Analysis

If you've configured a visual analysis model, you can analyze images in your Zettelkasten by asking the AI about them. For example:

  • "What's in the image at images/diagram.png?"
  • "Can you describe the chart in assets/sales-data.jpg?"
  • "Analyze the photo in attachments/meeting-whiteboard.png"

The AI will use the configured visual model to analyze the image and provide a description of its contents. This is particularly useful for:

  • Understanding diagrams and charts in your notes
  • Extracting text from images
  • Getting descriptions of visual content for reference
  • Analyzing screenshots or photos you've added to your knowledge base

Note: Visual analysis is only available if you've configured a visual model during setup.

🧠 Smart Memory

The tool includes a Smart Memory mechanism that allows the AI to store and retrieve information during conversations. This memory:

  • Persists between chat sessions
  • Uses vector embeddings for semantic similarity search
  • Enables the AI to recall previous context and information
  • Can be cleared using the --reset-memory CLI option

🖥️ Graphical Interface (Experimental)

The GUI is experimental and may not work as expected. It is provided as a preview feature only.

Note: The GUI has not yet been updated to use the new command-line vault path configuration. It still uses the old method of storing the configuration file in the user's home directory.

Run zkchat-gui to start the graphical interface. The GUI provides:

  • A multi-line chat input for composing messages
  • A scrollable chat history showing the entire conversation
  • A resizable divider between chat history and input areas
  • Settings menu (accessible via Settings -> Configure...) for:
    • Selecting the LLM model for chat from available models (based on the configured gateway)
    • Selecting an optional visual analysis model or disabling visual analysis
    • Configuring the Zettelkasten folder location
  • Asynchronous chat responses that keep the interface responsive

When first run, both zkchat and zkchat-gui will need initial configuration:

For the command-line interface:

  • You must provide the path to your Zettelkasten vault using the --vault argument
  • You can select which gateway to use (Ollama or OpenAI) with the --gateway argument
  • You'll be prompted to select an LLM model for chat from the available models for your chosen gateway (or you can specify it with --model)
  • You'll be asked if you want to select a visual analysis model (optional)

For the GUI:

  • You can configure these settings through the Settings menu
  • You can enable or disable visual analysis by selecting a model or choosing "None - Disable Visual Analysis"

After initial configuration, the tool will start a full index build of your Zettelkasten.

📁 Storage Location

The tool stores its configuration and database in your Zettelkasten vault:

  • .zk_chat - Configuration file stored in the vault root
  • .zk_chat_db/ - Chroma vector database folder stored in the vault root
  • ZkSystemPrompt.md - System prompt file created in the vault root if it doesn't exist. This file defines the behavior of the AI assistant and can be customized to change how the assistant interacts with your Zettelkasten. By default, this file is created and used. You can prevent the creation of this file by not using the --store-prompt parameter, in which case the default system prompt will be used.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zk_chat-3.0.0.tar.gz (57.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zk_chat-3.0.0-py3-none-any.whl (77.8 kB view details)

Uploaded Python 3

File details

Details for the file zk_chat-3.0.0.tar.gz.

File metadata

  • Download URL: zk_chat-3.0.0.tar.gz
  • Upload date:
  • Size: 57.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zk_chat-3.0.0.tar.gz
Algorithm Hash digest
SHA256 4639619bc5939bce43bb2cbcb238588380fcab9bd02167ac2c6fcd7c37eee1d8
MD5 000c3800e3967efa8a2aafa0ec9af06c
BLAKE2b-256 ab4f8f7cc580ace79bc34fc590aaee78b0c92a4b8bcd763c002fc534062301c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_chat-3.0.0.tar.gz:

Publisher: python-publish.yml on svetzal/zk-chat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_chat-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: zk_chat-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 77.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for zk_chat-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4c0f703190768d1e279fae7a493219fed137605f6eda1901a4ad9e1a4bebdc
MD5 2a931118388a66766987f619a9244003
BLAKE2b-256 df4b3fc113bc30b5bcbd7fd8bbcd6c0588892f55d91a5f74819c546a9a606c7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_chat-3.0.0-py3-none-any.whl:

Publisher: python-publish.yml on svetzal/zk-chat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page