ragless2
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

RAGless and RAGlessGraph

RAGless and RAGlessGraph are powerful code relevance systems for finding relevant files in your codebase. They use natural language processing, advanced search strategies, and code structure analysis to help you quickly locate the most pertinent files based on your query.

Features

Shared 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
  • Intelligent caching system for improved performance
  • File watching for real-time updates
  • Configurable logging with mute option
  • Command-line interface for interactive use
  • Programmable API for integration into other tools
  • Support for TypeScript and JavaScript projects

RAGless Specific Features

  • Basic search strategy optimized for general code search

RAGlessGraph Specific Features

  • Advanced search strategy using call graph analysis
  • Enhanced context understanding for more accurate results in complex codebases

Installation

You can install RAGless and RAGlessGraph using npm:

npm install ragless

Or using yarn:

yarn add ragless

Usage

Command-line Interface

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

npx ragless

This will start an interactive session where you can enter the directory to scan and your search queries. The CLI will provide results from both RAGless and RAGlessGraph for comparison.

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

npx ragless --mute

Programmatic Usage

You can use RAGless and RAGlessGraph as libraries in your Node.js projects:

import { RAGless, RAGlessGraph, 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);
const ragGraph = new RAGlessGraph(workingDir, logger);

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

// Later, when you want to search:
Promise.all([
  rag.findRelevantFiles('your query'),
  ragGraph.findRelevantFiles('your query')
]).then(([ragResults, ragGraphResults]) => {
  console.log('RAGless results:', ragResults);
  console.log('RAGlessGraph results:', ragGraphResults);
}).catch(error => {
  console.error('Error finding relevant files:', error);
});

API Reference

RAGless and RAGlessGraph Classes

Both classes have the same constructor and main method:

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 and RAGlessGraph in a Node.js script:

import { RAGless, RAGlessGraph, 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);
  const ragGraph = new RAGlessGraph(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 [ragResults, ragGraphResults] = await Promise.all([
        rag.findRelevantFiles(query, 3),
        ragGraph.findRelevantFiles(query, 3)
      ]);
      
      console.log(`\nTop 3 RAGless results for "${query}":`);
      ragResults.forEach((result, index) => {
        console.log(`${index + 1}. ${result.fileName} (Score: ${result.score.toFixed(2)})`);
      });
      
      console.log(`\nTop 3 RAGlessGraph results for "${query}":`);
      ragGraphResults.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 both RAGless and RAGlessGraph with the current working directory, performs searches for multiple queries, and prints the top 3 results from each implementation for each query.

Advanced Features

Caching

Both RAGless and RAGlessGraph use an intelligent caching system to improve performance. The cache is automatically managed and updated when files change. You can view cache information by checking the logs during initialization.

File Watching

The systems include a file watching feature that automatically updates the search index when files in the monitored directory change. This ensures that your search results are always up-to-date.

AST Analysis

Both implementations perform Abstract Syntax Tree (AST) analysis on JavaScript and TypeScript files to better understand the code structure. This improves search relevance for queries related to specific code constructs.

Call Graph Analysis (RAGlessGraph only)

RAGlessGraph builds a call graph of your codebase, analyzing function calls and relationships between different parts of your code. This allows for more context-aware searches, particularly useful in large and complex codebases.

Contributing

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

License

This project is licensed under the MIT License.

Package Sidebar

Install

npm i ragless2

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

98.4 kB

Total Files

48

Last publish

Collaborators

  • shaykec