npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ragless2

v1.0.3

Published

A code relevance system for finding relevant files

Downloads

6

Readme

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.