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.2.3.tar.gz (48.7 kB view details)

Uploaded Source

Built Distribution

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

ragdaemon-0.2.3-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragdaemon-0.2.3.tar.gz
  • Upload date:
  • Size: 48.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for ragdaemon-0.2.3.tar.gz
Algorithm Hash digest
SHA256 dba182745b9fa3b4f95299f01866f92a7f0ef54ab56e09cf2ecb967023b73856
MD5 c010c17821b1fea4edd93c1ad943159f
BLAKE2b-256 c5d99abaed73dc82b3fa903cc02514209553bdc13114b7ca46a008a7750cf6c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragdaemon-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 48.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for ragdaemon-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4e404773fe7eaa0a8927ad19a6ff09bd26e0d6213a7562ee9d3071c3c2276457
MD5 cf31fd503f13f8f1cc479bb1b87f2398
BLAKE2b-256 a5ebcaaf4e0cde6f2c0e7200fd1b6959a638b4636eed6fd9afe3e883227f4c8b

See more details on using hashes here.

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