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

@epicdm/flowstate-rag-client

v0.1.0

Published

RAG query client - semantic search and context building for FlowState

Readme

@epicdm/flowstate-rag-client

RAG query client library for FlowState - semantic search, context building, and memory recall.

Overview

This package provides a client library for querying the FlowState RAG (Retrieval-Augmented Generation) system. It connects to SurrealDB for vector similarity search and uses Ollama for text embeddings.

Features

  • Semantic Search - Query documents using natural language
  • Context Building - Build LLM-ready context strings from relevant documents
  • Memory Recall - Retrieve conversation history and agent memories
  • Document Similarity - Find related documents
  • Multi-tenancy - Workspace and organization filtering
  • Type-safe - Full TypeScript support with comprehensive type definitions

Installation

yarn add @epicdm/flowstate-rag-client

Usage

Basic Setup

import { RAGClient } from '@epicdm/flowstate-rag-client';

const client = new RAGClient({
  surrealdbUrl: 'ws://localhost:8000/rpc',
  surrealdbUser: 'root',
  surrealdbPass: 'root',
  surrealdbNamespace: 'flowstate',
  surrealdbDatabase: 'rag',
  ollamaUrl: 'http://localhost:11434',
  embeddingModel: 'nomic-embed-text'
});

await client.connect();

Semantic Search

const results = await client.search({
  query: 'What are the high priority bugs?',
  workspaceId: 'ws_1',
  collections: ['tasks', 'issues'],
  limit: 10,
  minScore: 0.7
});

for (const result of results) {
  console.log(`[${result.collection}] ${result.content} (score: ${result.score})`);
}

Context Building

Build a context string suitable for LLM consumption:

const context = await client.getContext({
  topic: 'What are the current sprint goals?',
  workspaceId: 'ws_1',
  includeMemories: true,
  maxTokens: 2000
});

console.log(context.context);
// "Based on the following information:
// [Task] Fix login bug - High priority...
// [Note] Sprint planning notes..."

console.log(`Token estimate: ${context.tokenEstimate}`);
console.log(`Sources: ${context.sources.length}`);

Memory Recall

Recall conversation history or agent memories:

const memories = await client.recall({
  topic: 'project requirements',
  namespace: 'user_123',
  sessionId: 'session_abc',
  limit: 10
});

for (const memory of memories.memories) {
  console.log(memory.content);
}

Find Similar Documents

Find documents similar to a given document:

const similar = await client.findSimilar({
  collection: 'tasks',
  docId: 'task_123',
  limit: 5,
  minScore: 0.8
});

console.log('Similar tasks:', similar);

Cleanup

await client.disconnect();

API Reference

RAGClient

Constructor

new RAGClient(config: RAGClientConfig)

Methods

  • connect(): Promise<void> - Connect to SurrealDB
  • disconnect(): Promise<void> - Close connection
  • isConnected(): boolean - Check connection status
  • search(options: SearchOptions): Promise<SearchResult[]> - Semantic search
  • getContext(options: ContextOptions): Promise<ContextResult> - Build context string
  • recall(options: RecallOptions): Promise<RecallResult> - Recall memories
  • findSimilar(options: FindSimilarOptions): Promise<SearchResult[]> - Find similar documents

Types

interface RAGClientConfig {
  surrealdbUrl: string;
  surrealdbUser: string;
  surrealdbPass: string;
  surrealdbNamespace: string;
  surrealdbDatabase: string;
  ollamaUrl: string;
  embeddingModel: string;
}

interface SearchResult {
  id: string;
  collection: string;
  docId: string;
  content: string;
  metadata: Record<string, unknown>;
  score: number;
}

interface ContextResult {
  context: string;
  sources: SearchResult[];
  tokenEstimate: number;
}

interface RecallResult {
  memories: SearchResult[];
}

Development

# Install dependencies
yarn install

# Build
yarn build

# Run tests
yarn test

# Run tests with coverage
yarn test:coverage

# Type check
yarn typecheck

# Lint
yarn lint
yarn lint:fix

Architecture

The RAGClient integrates with two external services:

  1. SurrealDB - Vector database for storing and querying document embeddings
  2. Ollama - Local LLM server for generating text embeddings
┌─────────────┐
│  RAGClient  │
└──────┬──────┘
       │
       ├──────────► SurrealDB (Vector Search)
       │
       └──────────► Ollama (Text Embeddings)

Requirements

  • Node.js 18+
  • SurrealDB server running (for vector storage)
  • Ollama server running with embedding model (e.g., nomic-embed-text)

Related Packages

  • @epicdm/flowstate-rag-sync - Syncs RxDB documents to RAG system
  • @epicdm/agent-memory-server - Manages agent conversation memory

License

Apache-2.0

Author

Epic Digital Interactive Media LLC