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 🙏

© 2026 – Pkg Stats / Ryan Hefner

contensis-rag-react

v0.3.4

Published

A lightweight set of React hooks for interacting with a Retrieval-Augmented Generation (RAG) backend using **Server-Sent Events (SSE)**.

Downloads

143

Readme

RAG React Hooks

A lightweight set of React hooks for interacting with a Retrieval-Augmented Generation (RAG) backend using Server-Sent Events (SSE).

This package provides two main hooks:

  • useRAGResponse – for single-turn responses (simple Q&A).
  • useRAGConversation – for multi-turn chat-like conversations with context.

It also includes a RAGProvider and context hooks for cleaner integration.


🚀 Installation

npm install contensis-rag-react
# or
yarn add contensis-rag-react

⚙️ Backend Configuration (baseUrl)

By default, the hooks expect your backend to be available at:

/contensis-ai-search/api/v1

You can override this using:

Via Context (Recommended)

Pass a baseUrl into the RAGProvider. This is the most flexible option, as it allows you to change URLs at runtime or between environments.

import { RAGProvider } from "contensis-rag-react";

function App() {
  return (
    <RAGProvider
      config="contensis-dev"
      baseUrl="https://my-api.example.com/api/v1"
    >
      <MyComponent />
    </RAGProvider>
  );
}

📦 Hooks Overview

useRAGResponse(collection: string)

Fetches a single response from the RAG backend. Best for Q&A without conversation history.

import { useRAGResponse } from "contensis-rag-react";

function QAComponent() {
  const { response, loading, error, ask } = useRAGResponse("contensis-dev");

  return (
    <div>
      <button onClick={() => ask("What is RAG?")}>Ask</button>
      {loading && <p>Loading...</p>}
      {error && <p>Error: {error}</p>}
      {response && <p>Answer: {response}</p>}
    </div>
  );
}

useRAGConversation(config: string)

Maintains a conversation history between user and assistant.

import { useRAGConversation } from "contensis-rag-react";

function ChatComponent() {
  const { messages, loading, error, ask } = useRAGConversation("contensis-dev");

  return (
    <div>
      <ul>
        {messages.map((msg, idx) => (
          <li key={idx}>
            <strong>{msg.role}:</strong> {msg.content}
          </li>
        ))}
      </ul>

      <button onClick={() => ask("Tell me about vector search.")}>Ask</button>

      {loading && <p>Loading...</p>}
      {error && <p>Error: {error}</p>}
    </div>
  );
}

🎯 Context-based Usage

Instead of passing config everywhere, wrap your app with RAGProvider:

import { RAGProvider } from "contensis-rag-react";

function App() {
  return (
    <RAGProvider config="contensis-dev">
      <MyComponent />
    </RAGProvider>
  );
}

Then use the context-aware hooks:

import {
  useRAGResponseContext,
  useRAGConversationContext,
} from "contensis-rag-react";

function MyComponent() {
  const { response, ask } = useRAGResponseContext();
  const { messages } = useRAGConversationContext();

  return (
    <div>
      <button onClick={() => ask("What is RAG?")}>Ask with Context</button>
      <pre>{response}</pre>

      <h4>Conversation</h4>
      {messages.map((m, i) => (
        <p key={i}>
          <b>{m.role}:</b> {m.content}
        </p>
      ))}
    </div>
  );
}

📖 API Reference

useRAGResponse(collection)

  • response: string – accumulated markdown text from assistant.
  • loading: boolean – true while waiting.
  • error: string | null – error message if failed.
  • ask(question: string): function to query backend.

useRAGConversation(collection)

  • messages: Message[] – array of { role: "user" | "assistant", content: string }.
  • loading: boolean.
  • error: string | null.
  • ask(question: string): function to send message and stream back assistant response.

RAGProvider

Props:

  • collection: string – the backend collection name.
  • baseUrl: string (optional) – API base URL. Defaults to /contensis-ai-search/api/v1.
  • children: React nodes.

useRAGResponseContext / useRAGConversationContext

Same as above, but auto-read collection and baseUrl from RAGProvider.