1.0.0 • Published 11 months ago

ragless v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

RAGless

RAGless is a powerful code relevance system for finding relevant files in your codebase. It uses natural language processing and advanced search strategies to help you quickly locate the most pertinent files based on your query.

Features

  • Fast and efficient code search across multiple file types
  • Natural Language Processing for improved search relevance
  • Abstract Syntax Tree (AST) parsing for better understanding of code structure
  • File watching for real-time updates
  • Configurable logging
  • Command-line interface for interactive use
  • Programmable API for integration into other tools

Installation

You can install RAGless using npm:

npm install ragless

Or using yarn:

yarn add ragless

Usage

Command-line Interface

After installation, you can use RAGless from the command line:

npx ragless

This will start an interactive session where you can enter the directory to scan and your search queries.

To mute logging output, use the --mute flag:

npx ragless --mute

Programmatic Usage

You can also use RAGless as a library in your Node.js projects:

import { RAGless, Logger } from 'ragless';

const logger: Logger = {
  info: (message: string) => console.log(`[INFO] ${message}`),
  warn: (message: string) => console.warn(`[WARN] ${message}`),
  error: (message: string, error?: any) => console.error(`[ERROR] ${message}`, error)
};

const workingDir = '/path/to/your/project';
const rag = new RAGless(workingDir, logger);

// To mute logging, pass true as the third argument
// const rag = new RAGless(workingDir, logger, true);

// Later, when you want to search:
rag.findRelevantFiles('your query').then(files => {
  console.log('Relevant files:', files);
}).catch(error => {
  console.error('Error finding relevant files:', error);
});

API Reference

RAGless Class

Constructor

constructor(workingDir: string, logger: Logger, muteLogging: boolean = false)
  • workingDir: The directory to scan for files
  • logger: An object implementing the Logger interface
  • muteLogging: If set to true, suppresses all logging output

Methods

findRelevantFiles(query: string, topN: number = 5): Promise<SearchResult[]>

Searches for files relevant to the given query.

  • query: The search query
  • topN: The maximum number of results to return (default: 5)

Returns a Promise that resolves to an array of SearchResult objects.

Logger Interface

interface Logger {
  info(message: string): void;
  warn(message: string): void;
  error(message: string, error?: any): void;
}

Implement this interface to provide custom logging behavior.

Example

Here's a more detailed example of how to use RAGless in a Node.js script:

import { RAGless, Logger } from 'ragless';

class CustomLogger implements Logger {
  info(message: string) { console.log(`[INFO] ${message}`); }
  warn(message: string) { console.warn(`[WARN] ${message}`); }
  error(message: string, error?: any) { console.error(`[ERROR] ${message}`, error); }
}

async function searchCode() {
  const logger = new CustomLogger();
  const workingDir = process.cwd();
  const rag = new RAGless(workingDir, logger);

  // Wait for initialization
  await new Promise(resolve => setTimeout(resolve, 2000));

  try {
    const queries = ['function', 'class', 'async', 'import'];
    for (const query of queries) {
      const results = await rag.findRelevantFiles(query, 3);
      console.log(`\nTop 3 results for "${query}":`);
      results.forEach((result, index) => {
        console.log(`${index + 1}. ${result.fileName} (Score: ${result.score.toFixed(2)})`);
      });
    }
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

searchCode();

This script initializes RAGless with the current working directory, performs searches for multiple queries, and prints the top 3 results for each query.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.