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 🙏

© 2024 – Pkg Stats / Ryan Hefner

prism-ai

v2.0.1

Published

Javascript wrapper for prism-ai (prism-ai.ch) - simple, powerful, RAG.

Downloads

3

Readme

Contributors Forks Stargazers Issues MIT License LinkedIn

Getting Started

Introduction to Prism

Prism is an innovative platform designed to simplify the integration of Retrieval Augmented Generation (RAG) capabilities into your applications. RAG combines the power of large language models with the ability to retrieve and incorporate information from knowledge sources seamlessly. It enhances the text generated by AI models, such as ChatGPT, Bard or Claude, by incorporating real-world knowledge.

RAG is a groundbreaking approach in the field of AI that allows developers to tap into the vast knowledge available in databases, websites, and files. By integrating this knowledge, developers can create AI systems that provide accurate and contextually relevant information. RAG is particularly valuable in tasks such as document search, question-answering, and chatbots, where understanding context and retrieving relevant information are crucial.

Vector embeddings, a key component of RAG systems, play a crucial role in capturing the semantic meaning of words and phrases. These embeddings transform text into high-dimensional numerical representations, enabling AI models to compare and identify similar information effectively. Vector embeddings have been instrumental in advancing RAG systems by providing a nuanced understanding of information and improving search capabilities.

Vector Embeddings are not Enough! Prism takes RAG to the next level by offering powerful Multidimensional Index Structures, Named Entity Recognition and subsequent Knowledge-Graph Retrieval, and more. Through Prism's intuitive API and libraries available in multiple languages, including Python and JavaScript, developers can quickly integrate RAG capabilities into their applications. Whether you are an expert or just getting started with language models, Prism's user-friendly platform simplifies the process of incorporating real-world knowledge into your AI applications.

Prerequisites

None. If you find it doesn't work without something please file an issue.

Installation and Setup

Prism is ready to go out of the box. The only major steps for setup are:

Install Prism with npm, pnpm, yarn, etc.

npm i prism-ai
pnpm i prism-ai
yarn prism-ai

Get an API Key

You can get an API Key only after being invited from the waitlist You can generate an API key by creating an account here and adding an API key directly in the application. Make sure to store it somewhere, you'll never see it again after it's created.

Add your API key and Prism's API url as environment variables

PRISM_API_KEY=rs_123...def
PRISM_API_URL=https://api.prism-ai.ch

Quick Start

Import Prism

import pai from 'prism-ai'

After installing prism, you can start adding knowledge bases, and generating replys based on the information contained within them:


const kb1 = pai.KnowledgeBase.create({
  name: "Online Information", 
  base_url: "https://www.my-website.com/",
})

const kb2 = pai.KnowledgeBase.create(
  name = "Local Information", 
  base_dir = "/path/to/relevant/directory"
)

const res = pai.Reply.stream(
  prompt: "Tell me about some of the information contained in the website and files.",
  kb_ids: [kb1.id, kb2.id].join(' ')
)

Resource Methods

Knowledge Bases

Create a Knowledge Base

Summary:

Knowledge bases provide the organizational structure of your textual information. Knowledge Bases contain individual Knowledges. This function is used to create a knowledge base.

Required Parameters:

*name: string - This is the name you will assign to your knowledge base.

Optional Parameters:

base_dir: string (default: None) - A path to a directory, where Prism should read files from. Every file from this directory will be processed as individual knowledges, to be added to the new knowledge base.

base_url: string (default: None) - A url from which Prism should extract relevant context. Only one of base_dir or base_url can be supplied. If both are supplied to the create function, an error will be thrown.

recursion: boolean (default: False) - Specifies whether knowledge should be added recursively

max_recursion: number (default: None) - Specifies the maximum number of files to read from a directory, or urls to scrape from links in the provided base_url.

only_base_url: boolean (default: True) - Specifies whether or not to scrape urls from links which point to network locations, other than the one supplied. For example, if only_base_url is set to True, and base_url is set to "https://www.prism-ai.ch/about/", then Prism will only create context from the urls it finds which also point to a network location belonging to prism-ai.ch. This argument will be ignored if used in combination with the base_dir argument.

kb_meta_context: string (default: None) - This string will be supplied to prompts with the context retrieved from this Knowledge Base, any time context is retrieved from this Knowledge Base. Adding relevant meta context, in general, significantly improves an LLM's ability to utilize context and synthesize information which is provided to it.

smart_index: boolean (default: False) - Specify whether or not to apply Prism's "Smart Index" to the resulting context data. In general, you should keep this option set to False unless you anticipate adding a large amount of information to this knowledge base. You can read more about Prism's Smart Index here.

ner: boolean (default: False) - Specify whether or not to extract named entities from provided text for use in Prism's knowledge graph retrieval engine.

Example Usage:

Create a Knowledge Base from information found on the internet:

kb:  pai.KnowledgeBase.create({
  name: "Online Prism Information", 
  base_url: "https://www.prism-ai.ch/",
  only_base_url: True, 
  recursion: True, 
  max_recursion: 100, 
  kb_meta_context: "This is information which was extracted from Prism's website",
  generate_meta_context: True,
  smart_index: False, 
  ner: True 
})

Create a Knowledge Base from information found on a local filesystem:

kb:  pai.KnowledgeBase.create({
  name: "Local Prism Information", 
  base_dir: "/path/to/relevant/directory",
  recursion: True, 
  kb_meta_context: "This is information which was extracted from local files belonging to Prism's team.",
  generate_meta_context: True,
  smart_index: False, 
  ner: True
})

Important Note: embedding, entity extraction, graph generation, and context organization takes some time, and happens asynchronously with your calls to the API. This means that you will recieve a response from create or add calls to both Knowledge and Knowledge Base objects before they are ready and available to be used for RAG. You can see the availability of your knowledge object at any time by running:

pai.Knowledge.get({ knowledge_id:your_knowledge_id })

Or alternatively you can retrieve the status of all your knowledge objects by running:

pai.info()

Add to an existing Knowledge Base

Summary:

Knowledge bases provide the organizational structure of your textual information. Knowledge Bases contain individual Knowledges. This function is used to add to an existing knowledge base.

Required Parameters:

kb_id: number - This is the ID of the knowledge base you wish to add knowledge to.

Optional Parameters:

base_dir: string (default: None) - A path to a directory, where Prism should read files from. Every file from this directory will be processed as individual knowledges, to be added to the new knowledge base.

base_url: string (default: None) - A url from which Prism should extract relevant context. Only one of base_dir or base_url can be supplied. If both are supplied to the create function, an error will be thrown.

recursion: boolean (default: False) - Specifies whether knowledge should be added recursively

max_recursion: number (default: None) - Specifies the maximum number of files to read from a directory, or urls to scrape from links in the provided base_url.

only_base_url: boolean (default: True) - Specifies whether or not to scrape urls from links which point to network locations, other than the one supplied. For example, if only_base_url is set to True, and base_url is set to "https://www.prism-ai.ch/about/", then Prism will only create context from the urls it finds which also point to a network location belonging to prism-ai.ch. This argument will be ignored if used in combination with the base_dir argument.

kb_meta_context: string (default: None) - This string will be supplied to prompts with the context retrieved from this Knowledge Base, any time context is retrieved from this Knowledge Base. Adding relevant meta context, in general, significantly improves an LLM's ability to utilize context and synthesize information which is provided to it.

generate_meta_context: boolean (default: True) - This setting determines whether or not to dynamically generate meta-context for each knowledge which is supplied to the knowledge base. Providing both kb_meta_context, and turning on generate_meta_context has been shown to significantly improve retrieval metrics, and subsequent generations.

smart_index: boolean (default: False) - Specify whether or not to apply Prism's "Smart Index" to the resulting context data. In general, you should keep this option set to False unless you anticipate adding a large amount of information to this knowledge base. You can read more about Prism's Smart Index here.

ner: boolean (default: False) - Specify whether or not to extract named entities from provided text for use in Prism's knowledge graph retrieval engine.

Example Usage:

Add information from the internet to an existing knowledge base:

kb:  pai.KnowledgeBase.add({
  kb_id: 1, 
  base_url: "https://www.prism-ai.ch/",
  only_base_url:  True, 
  recursion:  True, 
  max_recursion:  100, 
  kb_meta_context:  "This is information which was extracted from Prism's website",
  generate_meta_context:  True,
  smart_index:  False, 
  ner:  True 
})

Important Note: embedding, entity extraction, graph generation, and context organization takes some time, and happens asynchronously with your calls to the API. This means that you will recieve a response from create or add calls to both Knowledge and Knowledge Base objects before they are ready and available to be used for RAG. You can see the availability of your knowledge object at any time by running:

pai.Knowledge.get({ knowledge_id: your-knowledge-id })

Or alternatively you can retrieve the status of all your knowledge objects by running:

pai.info()

Get Details on a Specific Knowledge Base

Summary:

Here we provide a function for retrieve details about a specific knowledge base.

Required Parameters:

kb_id: number - This is the ID of the knowledge base you wish to add knowledge to.

Optional Parameters:

verbose: boolean (default: False) - Specify whether or not to include details about all knowledge objects contained within the specified knowledge base.

Example Usage:

Get details about a knowledge base, by knowledge base id, from Prism

pai.KnowledgeBase.get({
  kb_id:  1, 
  verbose:  False
})

Delete a Knowledge Base

Summary:

This function is used to delete a knowledge base. This action is irreversable and should be used with caution.

Required Parameters:

kb_id: number - This is the ID of the knowledge base you wish to delete.

Optional Parameters:

None

Example Usage:

pai.KnowledgeBase.delete({
  kb_id:  1
})

Knowledge

Create Knowledge

Summary:

Knowledges contain context for a LLM to use for improving generations. Every knowledge is contained within a single knowledge base. Knowledges can be created from a webpage, a file, a user-supplied string of text, or an audio / video file (coming soon).

Required Parameters:

method: string - Can be one of: "url", "text" or "file", indicating whether to grab knowledge from a url, from a user-supplied string, or a file, respectively. Supported filetypes are pdf, doc, docx, txt, odt and md. URLs must be prefixed with https or they will not be indexed.

name: string - The name you wish to give your knowledge.

kb_id: number - The ID of the knowledge base where you wish to create this knowledge.

source: string - The url, filesystem path, or user-supplied string which you wish to add to the knowledge base.

Optional Parameters:

meta_context: str (default: None) - This string will be supplied to prompts with the context retrieved from this Knowledge, any time context is retrieved from this Knowledge, in addition to the meta context attached to the parent knowledge base. Adding relevant meta context, in general, significantly improves an LLM's ability to utilize context and synthesize information which is provided to it. If meta_context is not supplied, meta_context will be automatically generated for the knowledge object in the background.

Example Usage:

Creating a knowledge from a url:

pai.Knowledge.create({
  method:  "url", 
  name:  "Knowledge about Prism", 
  kb_id:  1, 
  source:  "https://www.prism-ai.ch/",
  meta_context:  "This is information retrieved from the Prism website."
})

Creating a knowledge from a file:

pai.Knowledge.create({
  method:  "file", 
  name:  "Knowledge about Prism", 
  kb_id:  1, 
  source:  "/path/to/prism.pdf",
  meta_context:  "This is information retrieved from the Prism documentation."
})

Creating a knowledge from text:

pai.Knowledge.create({
  method:  "text", 
  name:  "Knowledge about Prism", 
  kb_id:  1, 
  source:  "Did you know that Prism supports fully private instances? That means nobody but you ever touches your data!",
  meta_context:  "This is information retrieved from the Prism documentation."
})

Important Note: embedding, entity extraction, graph generation, and context organization takes some time, and happens asynchronously with your calls to the API. This means that you will recieve a response from create or add calls to both Knowledge and Knowledge Base objects before they are ready and available to be used for RAG. You can see the availability of your knowledge object at any time by running:

pai.Knowledge.get({ knowledge_id: your-knowledge-id })

Or alternatively you can retrieve the status of all your knowledge objects by running:

pai.info()

Delete

Summary:

This function is used to delete a knowledge. This action is irreversable and should be used with caution.

Required Parameters:

knowledge_id: number - This is the ID of the knowledge you wish to delete.

Optional Parameters:

None

Example Usage:

pai.Knowledge.delete({
  knowledge_id:  1
})

Reply

Summary:

This endpoint allows you to forward context directly to the LLM of your choice. Using Reply objects is more powerful, and usually faster, than retrieving context and sending to an LLM yourself. This is due in part to the various prompt schemas we have tested and created meticulously to maximize performance in the backend, as well as the remaining part of our RAG pipeline which get's dropped when retrieving context directly to your own internal application.

Create a Reply

Summary:

This endpoint allows you to generate a reply from the LLM of your choice.

Required Parameters:

prompt: string - This provides a prompt for the LLM from which to generate a reply.

Optional Parameters:

kb_id: List[number] (default: []) - A list of knowledge base ids from which to retrieve relevant context.

model: string (coming soon) - An LLM to use for generating a reply. In the very near future, we aim to offer every model available from OpenAI, Anthropic, Minstral, Google, Meta, and more.

hyde: boolean (default: False) - Here you can indicate whether you would like to run the HyDE algorithm for RAG. This option is good for short prompts contianing little context to search for.

Example Usage:

Create a reply using some knowledge base:

const reply = pai.Reply.create({
  prompt:  "Tell me something Interesting that about prism-ai.",
  knowledge_base:  [1],
  hyde:  True
})

Create a Reply Stream

Summary:

This endpoint allows you to generate a reply stream from the LLM of your choice.

Required Parameters:

prompt: string - This provides a prompt for the LLM from which to generate a reply.

Optional Parameters:

kb_id: List[number] (default: []) - A list of knowledge base ids from which to retrieve relevant context.

model: string (coming soon) - An LLM to use for generating a reply. In the very near future, we aim to offer every model available from OpenAI, Anthropic, Minstral, Google, Meta, and more.

hyde: boolean (default: False) - Here you can indicate whether you would like to run the HyDE algorithm for RAG. This option is good for short prompts contianing little context to search for.

Example Usage:

Create a reply using some knowledge base:


const stream = pai.Reply.stream({
  prompt:  "Tell me something Interesting that about prism-ai.",
  knowledge_base:  [1],
  hyde:  True
})

Context

get

Summary:

Contexts are strings of raw text which has ben harvested from a document, url, or other source of textual information. Contexts belong to knowledge objects. The context endpoint provides an interface for interacting with the context you've created, and performing RAG manually.

Required Parameters:

kb_id: List[number] - Specify a list of knowledge base ids from which to extract contexts.

prompt: string - The text to use for context search.

Optional Parameters:

n: number (default: 1) - Specify the number of contexts to retrieve from the knowledge base.

hyde: boolean (default: False) - Specify whether or not to use the hyde algorithm for context retrieval.

Example Usage:

Extract context from your knowledge base:


context:  pai.Context.get({
  kb_id:  [1, 2, 3],
  prompt:  "Here is a prompt that we'll use to search over the knowledge bases specified",
  n:  10, 
  hyde:  True
})

Roadmap

  • [ ] Feature 1
  • [ ] Feature 2
  • [ ] Feature 3
    • [ ] Nested Feature

See the open issues for a full list of proposed features (and known issues).

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Prism AI - [email protected]

Project Link: https://github.com/The-Prism-AI/npm-prism-ai

Acknowledgments