Package: prism-ai
Prism AIPrism AI empowers developers to easily implement A.I.-powered search and retrieval augmented generation, in just a few lines of code.Explore the docs »·Report Bug·Request FeatureAbout The ProjectPrismis 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.RAGis 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 powerfulMultidimensional Index Structures,Named Entity Recognitionand subsequentKnowledge-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.(back to top)Getting StartedPrerequisitesYou'll need python version 3.7 or higher to use the Prism AI API wrapper.Installation and SetupPrism is ready to go out of the box. The only major steps for setup are:Install Prism with pippipinstallprism_aiGet an API KeyYou can generate an API key by creating an accounthereand 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 as an environment variableexportPRISM_API_KEY=rs_123...defOr to set your API key directly in python you can run:importprism_aiaspaipai.api_key="rs_123...def"Quick StartAfter installing prism, you can start adding knowledge bases, and generating replys based on the information contained within them:kb1=pai.KnowledgeBase.create(name="Online Information",base_url="https://www.my-website.com/",)kb2=pai.KnowledgeBase.create(name="Local Information",base_dir="/path/to/relevant/directory")reply=pai.Reply.stream(prompt="Tell me about some of the information contained in the website and files.",kb_ids=[kb1.id,kb2.id])Standalone MethodsInfopai.info()SummaryAssuming the API key has been specified and you have a stable connection to the internet, the info function will return a breakdown of the user info, as well as the knowledge-graph tree containing a list of all knowledge bases, and a list of all contained knowledges for each knowledge base.This function has no required or optional parameters.Resource MethodsKnowledge BasesCreate a Knowledge BaseSummary: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: str- This is the name you will assign to your knowledge base.Optional Parameters:base_dir: str (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: str (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: bool (default: False)- Specifies whether knowledge should be added recursivelymax_recursion: int (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: bool (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: str (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: bool (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 Indexhere.ner: bool (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:print(pai.Knowledge.get(knowledge_id=int(your_knowledge_id)))Or alternatively you can retrieve the status of all your knowledge objects by running:pai.info()Add to an existing Knowledge BaseSummary: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: int- This is the ID of the knowledge base you wish to add knowledge to.Optional Parameters:base_dir: str (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: str (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: bool (default: False)- Specifies whether knowledge should be added recursivelymax_recursion: int (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: bool (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: str (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: bool (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: bool (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 Indexhere.ner: bool (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:print(pai.Knowledge.get(knowledge_id=int(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 BaseSummary:Here we provide a function for retrieve details about a specific knowledge base.Required Parameters:kb_id: int- This is the ID of the knowledge base you wish to add knowledge to.Optional Parameters:verbose: bool (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 Prismpai.KnowledgeBase.get(kb_id=1,verbose=False)Delete a Knowledge BaseSummary:This function is used to delete a knowledge base. This action is irreversable and should be used with caution.Required Parameters:kb_id: int- This is the ID of the knowledge base you wish to delete.Optional Parameters:NoneExample Usage:kb=pai.KnowledgeBase.delete(kb_id=1)KnowledgeCreate KnowledgeSummary: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: str- 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: str- The name you wish to give your knowledge.kb_id: int- The ID of the knowledge base where you wish to create this knowledge.source: str- 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:knowledge=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:knowledge=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 a file:knowledge=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:print(pai.Knowledge.get(knowledge_id=int(your_knowledge_id)))Or alternatively you can retrieve the status of all your knowledge objects by running:pai.info()DeleteSummary:This function is used to delete a knowledge. This action is irreversable and should be used with caution.Required Parameters:knowledge_id: int- This is the ID of the knowledge you wish to delete.Optional Parameters:NoneExample Usage:to_delete=pai.Knowledge.delete(knowledge_id=1)ReplySummary: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 ReplySummary:This endpoint allows you to generate a reply from the LLM of your choice.Required Parameters:prompt: str- This provides a prompt for the LLM from which to generate a reply.Optional Parameters:kb_id: List[int] (default: [])- A list of knowledge base ids from which to retrieve relevant context.model: str (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: bool (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:reply=pai.Reply.create(prompt="Tell me something Interesting that about prism-ai.",knowledge_base=[1],hyde=True)Create a Reply StreamSummary:This endpoint allows you to generate a reply stream from the LLM of your choice.Required Parameters:prompt: str- This provides a prompt for the LLM from which to generate a reply.Optional Parameters:kb_id: List[int] (default: [])- A list of knowledge base ids from which to retrieve relevant context.model: str (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: bool (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:stream=pai.Reply.stream(prompt="Tell me something Interesting that about prism-ai.",knowledge_base=[1],hyde=True)forchunkinstream:# handle the chunkpassContextgetSummary: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[int]- Specify a list of knowledge base ids from which to extract contexts.prompt: str- The text to use for context search.Optional Parameters:n: int (default: 1)- Specify the number of contexts to retrieve from the knowledge base.hyde: bool (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)(back to top)ContributingIf 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!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull Request(back to top)LicenseDistributed under the MIT License. SeeLICENSE.txtfor more information.(back to top)ContactPrism AI -info@prism-ai.chProject Link:https://github.com/The-Prism-AI/Prism-AI(back to top)