Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit dc0b06e

Browse files
authored
Merge pull request #35 from SciPhi-AI/Nolan/Release1.1.0
1.1.0 Release
2 parents d6cde4c + 59dc0c7 commit dc0b06e

File tree

11 files changed

+349
-97
lines changed

11 files changed

+349
-97
lines changed

README.md

Lines changed: 184 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,217 @@
1-
# R2R JavaScript Client
1+
<p align="left">
2+
<a href="https://r2r-docs.sciphi.ai"><img src="https://img.shields.io/badge/docs.sciphi.ai-3F16E4" alt="Docs"></a>
3+
<a href="https://discord.gg/p6KqD2kjtB"><img src="https://img.shields.io/discord/1120774652915105934?style=social&logo=discord" alt="Discord"></a>
4+
<a href="https://github.com/SciPhi-AI/R2R"><img src="https://img.shields.io/github/stars/SciPhi-AI/R2R" alt="Github Stars"></a>
5+
<a href="https://github.com/SciPhi-AI/R2R/pulse"><img src="https://img.shields.io/github/commit-activity/w/SciPhi-AI/R2R" alt="Commits-per-week"></a>
6+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-purple.svg" alt="License: MIT"></a>
7+
<a href="https://www.npmjs.com/package/r2r-js"><img src="https://img.shields.io/npm/v/r2r-js.svg" alt="npm version"></a>
8+
</p>
29

3-
[![npm version](https://img.shields.io/npm/v/r2r-js.svg)](https://www.npmjs.com/package/r2r-js)
4-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10+
<img src="https://raw.githubusercontent.com/SciPhi-AI/R2R/main/assets/r2r.png" alt="R2R JavaScript Client">
11+
<h3 align="center">
12+
The ultimate open source RAG answer engine - JavaScript Client
13+
</h3>
514

6-
This repository contains a JavaScript client for the R2R (RAG to Riches) framework. R2R is a powerful tool for building, deploying, and optimizing RAG (Retrieval-Augmented Generation) systems.
15+
# About
716

8-
## About R2R
17+
The official JavaScript client for R2R (Retrieval-Augmented Generation to Riches). R2R is designed to bridge the gap between local LLM experimentation and scalable, production-ready Retrieval-Augmented Generation (RAG). This JavaScript client provides a seamless interface to interact with the R2R RESTful API.
918

10-
R2R provides a fast and efficient way to deliver high-quality RAG to end-users. The framework is built around customizable pipelines and a feature-rich FastAPI implementation.
19+
For a more complete view of R2R, check out the [full documentation](https://r2r-docs.sciphi.ai/).
1120

12-
Key features of R2R include:
21+
## Key Features
1322

14-
- Instant deployment of production-ready RAG pipelines with streaming capabilities
15-
- Customizable pipelines with intuitive configuration files
16-
- Extensibility with custom code integrations
17-
- Autoscaling capabilities in the cloud using SciPhi
18-
- Open-source framework developed by the community to simplify RAG deployment
23+
- **📁 Multimodal Support**: Ingest files ranging from `.txt`, `.pdf`, `.json` to `.png`, `.mp3`, and more.
24+
- **🔍 Hybrid Search**: Combine semantic and keyword search with reciprocal rank fusion for enhanced relevancy.
25+
- **🔗 Graph RAG**: Automatically extract relationships and build knowledge graphs.
26+
- **🗂️ App Management**: Efficiently manage documents and users with rich observability and analytics.
27+
- **🌐 Client-Server**: RESTful API support out of the box.
28+
- **🧩 Configurable**: Provision your application using intuitive configuration files.
29+
- **🔌 Extensible**: Develop your application further with easy builder + factory pattern.
30+
- **🖥️ Dashboard**: Use the [R2R Dashboard](https://github.com/SciPhi-AI/R2R-Dashboard), an open-source React+Next.js app for a user-friendly interaction with R2R.
1931

20-
For more information about R2R, please refer to the [R2R documentation](https://r2r-docs.sciphi.ai).
32+
## Table of Contents
2133

22-
## Installation
34+
1. [Install](#install)
35+
2. [R2R JavaScript Client Quickstart](#r2r-javascript-client-quickstart)
36+
3. [Community and Support](#community-and-support)
37+
4. [Contributing](#contributing)
2338

24-
To install the R2R JavaScript client, run the following command:
39+
# Install
2540

26-
```
41+
```bash
2742
npm install r2r-js
2843
```
2944

30-
## Usage
45+
# R2R JavaScript Client Quickstart
46+
47+
## Initialize the R2R client
48+
49+
```javascript
50+
const { r2rClient } = require("r2r-js");
51+
52+
const client = new r2rClient("http://localhost:8000");
53+
```
54+
55+
## Ingest files
3156

32-
Here's a basic example of how to use the R2R JavaScript client:
57+
```javascript
58+
const files = [
59+
{ path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" },
60+
{ path: "examples/data/karamozov.txt", name: "karamozov.txt" },
61+
];
62+
63+
const ingestResult = await client.ingestFiles(files, {
64+
metadatas: [{ title: "raskolnikov.txt" }, { title: "karamozov.txt" }],
65+
user_ids: [
66+
"123e4567-e89b-12d3-a456-426614174000",
67+
"123e4567-e89b-12d3-a456-426614174000",
68+
],
69+
skip_document_info: false,
70+
});
71+
console.log(ingestResult);
72+
```
73+
74+
## Perform a search
3375

3476
```javascript
35-
import { R2RClient } from "r2r-js";
77+
const searchResult = await client.search("Who was Raskolnikov?");
78+
console.log(searchResult);
79+
```
3680

37-
const baseUrl = "http://localhost:8000";
38-
const client = new R2RClient(baseUrl);
81+
## Perform RAG
82+
83+
```javascript
84+
const ragResult = await client.rag({
85+
query: "Who was Raskolnikov?",
86+
use_vector_search: true,
87+
search_filters: {},
88+
search_limit: 10,
89+
do_hybrid_search: false,
90+
use_kg_search: false,
91+
kg_generation_config: {},
92+
rag_generation_config: {
93+
model: "gpt-4o",
94+
temperature: 0.0,
95+
stream: false,
96+
},
97+
});
98+
console.log(ragResult);
99+
```
100+
101+
## Stream a RAG Response
102+
103+
```javascript
104+
const streamingRagResult = await client.rag({
105+
query: "Who was Raskolnikov?",
106+
rag_generation_config: {
107+
stream: true,
108+
},
109+
});
110+
111+
if (streamingRagResult instanceof ReadableStream) {
112+
const reader = streamingRagResult.getReader();
113+
while (true) {
114+
const { done, value } = await reader.read();
115+
if (done) break;
116+
console.log(new TextDecoder().decode(value));
117+
}
118+
}
119+
```
120+
121+
# Hello r2r-js
122+
123+
Building with the R2R JavaScript client is easy - see the `hello_r2r` example below:
124+
125+
```javascript
126+
const { r2rClient } = require("r2r-js");
127+
128+
const client = new r2rClient("http://localhost:8000");
39129

40130
async function main() {
41-
// Perform a health check
42-
const healthCheck = await client.healthCheck();
43-
console.log("Health check:", healthCheck);
44-
45-
// Ingest documents
46-
const ingestRequest = {
47-
texts: ["Sample text 1", "Sample text 2"],
48-
metadatas: [{ source: "file1" }, { source: "file2" }],
49-
ids: ["doc1", "doc2"],
50-
};
51-
const ingestResponse = await client.ingestDocuments(ingestRequest);
52-
console.log("Ingest response:", ingestResponse);
53-
54-
// Perform a search
55-
const searchRequest = {
56-
query: "your search query",
57-
n_results: 5,
58-
};
59-
const searchResponse = await client.search(searchRequest);
60-
console.log("Search response:", searchResponse);
61-
62-
// Perform a RAG completion
63-
const ragRequest = {
64-
query: "your query",
65-
n_results: 5,
66-
};
67-
const ragResponse = await client.rag(ragRequest);
68-
console.log("RAG response:", ragResponse);
131+
const files = [
132+
{ path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" },
133+
];
134+
135+
console.log("Ingesting file...");
136+
const ingestResult = await client.ingestFiles(files, {
137+
metadatas: [{ title: "raskolnikov.txt" }],
138+
user_ids: ["123e4567-e89b-12d3-a456-426614174000"],
139+
skip_document_info: false,
140+
});
141+
console.log("Ingest result:", JSON.stringify(ingestResult, null, 2));
142+
143+
console.log("Performing RAG...");
144+
const ragResponse = await client.rag({
145+
query: "What does the file talk about?",
146+
rag_generation_config: {
147+
model: "gpt-4o",
148+
temperature: 0.0,
149+
stream: false,
150+
},
151+
});
152+
153+
console.log("Search Results:");
154+
ragResponse.results.search_results.vector_search_results.forEach(
155+
(result, index) => {
156+
console.log(`\nResult ${index + 1}:`);
157+
console.log(`Text: ${result.metadata.text.substring(0, 100)}...`);
158+
console.log(`Score: ${result.score}`);
159+
},
160+
);
161+
162+
console.log("\nCompletion:");
163+
console.log(ragResponse.results.completion.choices[0].message.content);
69164
}
70165

71-
main().catch((error) => console.error(error));
166+
main();
72167
```
73168

74-
For more detailed usage examples and API documentation, please refer to the [R2R documentation](https://r2r-docs.sciphi.ai/introduction).
169+
And the results:
170+
171+
```bash
172+
Ingesting file...
173+
Ingest result: {
174+
"results": {
175+
"processed_documents": [
176+
"File 'raskolnikov.txt' processed successfully."
177+
],
178+
"failed_documents": [],
179+
"skipped_documents": []
180+
}
181+
}
182+
Performing RAG...
183+
Search Results:
184+
185+
Result 1:
186+
Text: praeterire culinam eius, cuius ianua semper aperta erat, cogebatur. Et quoties praeteribat,
187+
iuvenis ...
188+
Score: 0.08281802143835804
75189

76-
## Features
190+
Result 2:
191+
Text: In vespera praecipue calida ineunte Iulio iuvenis e cenaculo in quo hospitabatur in
192+
S. loco exiit et...
193+
Score: 0.052743945852283036
77194

78-
The R2R JavaScript client supports various operations:
195+
Completion:
196+
The file discusses the experiences of a young man who is burdened by debt and is staying in a small room in a tall house. He feels anxious and ashamed whenever he passes by the kitchen, where the door is always open, and he is particularly worried about encountering his landlady, who provides him with meals and services. The young man tries to avoid meeting her, especially when he leaves his room, which is more like a closet than a proper room [1], [2].
197+
```
79198

80-
- Health check
81-
- Update prompt
82-
- Ingest documents and files
83-
- Update documents and files
84-
- Search
85-
- RAG (Retrieval-Augmented Generation)
86-
- Delete documents
87-
- Retrieve logs
88-
- Get app settings
89-
- Analytics
90-
- Users overview
91-
- Documents overview
92-
- Document chunks
199+
# Community and Support
93200

94-
Each feature is implemented as a method in the `R2RClient` class, allowing for easy integration with your application.
201+
- [Discord](https://discord.gg/p6KqD2kjtB): Chat live with maintainers and community members
202+
- [Github Issues](https://github.com/SciPhi-AI/R2R-js/issues): Report bugs and request features
95203

96-
## Contributing
204+
**Explore our [R2R Docs](https://r2r-docs.sciphi.ai/) for tutorials and cookbooks on various R2R features and integrations.**
97205

98-
Contributions to the R2R JavaScript client are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
206+
# Contributing
99207

100-
## License
208+
We welcome contributions of all sizes! Here's how you can help:
101209

102-
The R2R JavaScript client is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).
210+
- Open a PR for new features, improvements, or better documentation.
211+
- Submit a [feature request](https://github.com/SciPhi-AI/R2R-js/issues/new?assignees=&labels=&projects=&template=feature_request.md&title=) or [bug report](https://github.com/SciPhi-AI/R2R-js/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=)
103212

104-
## Contributing
213+
### Our Contributors
105214

106-
We welcome contributions of all sizes!
215+
<a href="https://github.com/SciPhi-AI/R2R/graphs/contributors">
216+
<img src="https://contrib.rocks/image?repo=SciPhi-AI/R2R" />
217+
</a>

0 commit comments

Comments
 (0)