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

ragless

v1.0.0

Published

A code relevance system for finding relevant files

Downloads

5

Readme

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.