# ragless2

> A code relevance system for finding relevant files

Latest version **1.0.3** (published 2024-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install ragless2
pnpm add ragless2
yarn add ragless2
bun add ragless2
```

Provides the command `ragless`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-08-14 |
| First published | 2024-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 96.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Your Name |
| Maintainers | shaykec |
| Keywords | code, search, relevance, rag |

## Links

- npm: https://www.npmjs.com/package/ragless2
- npm.io page: https://npm.io/package/ragless2

## Dependencies (6)

- [user](https://npm.io/package/user.md) ^0.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [natural](https://npm.io/package/natural.md) ^6.5.0
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^7.25.3
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) ^7.25.3

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2024-08-14
- 1.0.2 — 2024-08-14
- 1.0.1 — 2024-08-14

## 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:

```bash
npm install ragless
```

Or using yarn:

```bash
yarn add ragless
```

## Usage

### Command-line Interface

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

```bash
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:

```bash
npx ragless --mute
```

### Programmatic Usage

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

```typescript
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

```typescript
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

```typescript
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:

```typescript
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.

---
_Source: https://npm.io/package/ragless2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
