The official JavaScript client for R2R (Retrieval-Augmented Generation to Riches). R2R is designed to bridge the gap between local LLM experimentation and scalable, state of the art Retrieval-Augmented Generation (RAG). This JavaScript client provides a seamless interface to interact with the R2R RESTful API.
For a more complete view of R2R, check out the full documentation.
-
📁 Multimodal Support: Ingest files ranging from
.txt
,.pdf
,.json
to.png
,.mp3
, and more. - 🔍 Hybrid Search: Combine semantic and keyword search with reciprocal rank fusion for enhanced relevancy.
- 🔗 Graph RAG: Automatically extract relationships and build knowledge graphs.
- 🗂️ App Management: Efficiently manage documents and users with rich observability and analytics.
- 🌐 Client-Server: RESTful API support out of the box.
- 🧩 Configurable: Provision your application using intuitive configuration files.
- 🔌 Extensible: Develop your application further with easy builder + factory pattern.
- 🖥️ Dashboard: Use the R2R Dashboard, an open-source React+Next.js app for a user-friendly interaction with R2R.
npm install r2r-js
const { r2rClient } = require("r2r-js");
const client = new r2rClient("http://localhost:7272");
const EMAIL = "admin@example.com";
const PASSWORD = "change_me_immediately";
console.log("Logging in...");
await client.login(EMAIL, PASSWORD);
const files = [
{ path: "examples/data/raskolnikov.txt", name: "raskolnikov.txt" },
{ path: "examples/data/karamozov.txt", name: "karamozov.txt" },
];
const ingestResult = await client.ingestFiles(files, {
metadatas: [{ title: "raskolnikov.txt" }, { title: "karamozov.txt" }],
user_ids: [
"123e4567-e89b-12d3-a456-426614174000",
"123e4567-e89b-12d3-a456-426614174000",
],
});
console.log(ingestResult);
const searchResult = await client.search("Who was Raskolnikov?");
console.log(searchResult);
const ragResult = await client.rag({
query: "Who was Raskolnikov?",
use_vector_search: true,
filters: {},
search_limit: 10,
use_hybrid_search: false,
use_kg_search: false,
kg_generation_config: {},
rag_generation_config: {
model: "gpt-4o",
temperature: 0.0,
stream: false,
},
});
console.log(ragResult);
const streamingRagResult = await client.rag({
query: "Who was Raskolnikov?",
rag_generation_config: {
stream: true,
},
});
if (streamingRagResult instanceof ReadableStream) {
const reader = streamingRagResult.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(new TextDecoder().decode(value));
}
}
- Discord: Chat live with maintainers and community members
- Github Issues: Report bugs and request features
Explore our R2R Docs for tutorials and cookbooks on various R2R features and integrations.
We welcome contributions of all sizes! Here's how you can help:
- Open a PR for new features, improvements, or better documentation.
- Submit a feature request or bug report