Skip to main content

Generate and render a call graph for a Python project.

Project description

Ragdaemon

Ragdaemon is a Retrieval-Augmented Generation (RAG) system for code. It runs a daemon (background process) to watch your active code, put it in a knowledge graph, and query the knowledge graph to (among other things) generate context for LLM completions.

Three ways to use Ragdaemon:

1. Help me write code

Ragdaemon powers the 'auto-context' feature in Mentat, a command-line coding assistant. You can install Mentat using pip install mentat. Run with the --auto-context-tokens <amount> or -a (default=5000) flag, and ragdaemon-selected context will be added to all of your prompts.

2. Explore the knowledge graph

Install locally to visualize and query the knowledge graph directly. Install using pip install ragdaemon, and run in your codebase's directory, e.g. ragdaemon. This will start a Daemon on your codebase, and an interface at localhost:5001. Options:

  • --chunk-extensions <ext>[..<ext>]: Which file extensions to chunk. If not specified, defaults to the top 20 most common code file extensions.
  • --chunk-model: OpenAI's gpt-4-0215-preview by default.
  • --embeddings-model: OpenAI's text-embedding-3-large by default.
  • --diff: A git diff to include in the knowledge graph. By default, the active diff (if any) is included with each code feature.

3. Use ragdaemon Python API

Ragdaemon is released open-source as a standalone RAG system. It includes a library of python classes to generate and query the knowledge graph. The graph itself is a NetworkX MultiDiGraph which saves/loads to a .json file.

import asyncio
from pathlib import Path
from ragdaemon.daemon import Daemon

async def main():
    cwd = Path.cwd()
    daemon = Daemon(cwd)
    await daemon.update()

    results = daemon.search("javascript")
    for result in results:
        print(f"{result['distance']} | {result['id']}")

    query = "How do I run the tests?"
    context_builder = daemon.get_context(
        query, 
        auto_tokens=5000
    )
    context = context_builder.render()
    messages = [
        {"role": "user", "content": query},
        {"role": "user", "content": f"CODE CONTEXT\n{context}"}
    ]
    print(messages)

asyncio.run(main())

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

ragdaemon-0.8.2.tar.gz (91.8 kB view details)

Uploaded Source

Built Distribution

ragdaemon-0.8.2-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file ragdaemon-0.8.2.tar.gz.

File metadata

  • Download URL: ragdaemon-0.8.2.tar.gz
  • Upload date:
  • Size: 91.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for ragdaemon-0.8.2.tar.gz
Algorithm Hash digest
SHA256 4a7b7c3af242497edcf50fc6c59aa9574e9f47b2e9713476c7c702c6c4d94762
MD5 779035df12623394ea07d1780b14934c
BLAKE2b-256 1ff55f80047a099db4d1309972a2f71d06178331859f45844bac384753070f26

See more details on using hashes here.

File details

Details for the file ragdaemon-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: ragdaemon-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for ragdaemon-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7230754d13b93ccc4ee9eb3413487c276fe34c5d0c1a6413d498e4d8b34fea58
MD5 432ad0ac4b92a7b7525a983fa2696dd9
BLAKE2b-256 f03e9dcb56446b6b194fa6d9831ee2ae0a5a3421ba7b3b29ba18a6b4448d5788

See more details on using hashes here.

Supported by

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