Integrate Cogniswitch for Knowledge Management
LlamaIndex tool that lets an agent store documents or URLs in CogniSwitch and answer questions from that knowledge.
Why it matters
Seamlessly integrate your knowledge base with Cogniswitch to build production-ready applications. Alleviate decision-making stress regarding storage and retrieval, and eradicate reliability issues and hallucinations in AI-generated responses.
Outcomes
What it gets done
Instantiate the Cogniswitch ToolSpec with your API credentials.
Store data by providing file paths or URLs to the agent.
Query your knowledge store for answers to specific questions.
Monitor document processing status within the Cogniswitch console.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-tool-tools-cogniswitch | bash Overview
os.environ["OPENAI_API_KEY"] = <your openai token>
CogniSwitch ToolSpec gives a LlamaIndex agent a managed knowledge store: hand it a file or URL to ingest, check processing status, then ask questions answered from what has been stored. It aims to reduce hallucinations versus a hand-rolled retrieval pipeline. Use it when an agent needs to build and query a persistent knowledge store from documents or URLs. It requires a CogniSwitch account with a platform token and OAuth token.
What it does
CogniSwitch ToolSpec lets a LlamaIndex agent consume, organize, and retrieve knowledge through the CogniSwitch platform. CogniSwitch describes itself as a technology platform that enhances the reliability of generative AI applications for enterprises by gathering and organizing knowledge from documented sources and eliminating hallucinations and bias in AI responses, so the toolspec exists to take storage-and-retrieval-format decisions off the developer's plate. Getting started follows four labeled steps in the source -- "Instantiate the Cogniswitch ToolSpec," "Instantiate the Agent," "Cogniswitch Store data," and "Cogniswitch Answer" -- covering: instantiate the CogniswitchToolSpec with a CogniSwitch platform token, an OpenAI API key, and an OAuth token; instantiate an agent (for example a ReActAgent) with the toolspec's tool list; store data by handing the agent a file path or URL, which it processes and stores in your CogniSwitch knowledge store; and answer queries by handing the agent a question, which it answers from that stored knowledge.
When to use - and when NOT to
Use it when you want an agent to build a persistent knowledge store from documents or URLs and then answer questions grounded in that store, without hand-rolling your own retrieval pipeline. It requires a CogniSwitch account -- signing up with email verification at cogniswitch.ai/developer to receive a platform token and OAuth token by email -- so it is not usable without first registering.
Inputs and outputs
Setup takes a CogniSwitch platform token (cs_token), an OpenAI API key, and a CogniSwitch OAuth token (apiKey):
from llama_index.tools.cogniswitch import CogniswitchToolSpec
from llama_index.core.agent import ReActAgent
toolspec = CogniswitchToolSpec(cs_token=cs_token, apiKey=oauth_token)
tool_lst = toolspec.to_tool_list()
agent = ReActAgent.from_tools(tool_lst)
From there, a single agent.chat(...) call handles each job. Storing a URL returns a response shaped like {'data': {'knowledgeSourceId': 43, 'sourceType': 'https://cogniswitch.ai/developer', 'sourceName': 'Cogniswitch dev', 'status': 'UPLOADED'}, 'message': "We're processing your content & will send you an email on completion, hang tight!"}. A follow-up status call, agent.chat("Tell me the status of Cogniswitch Developer Website"), returns plain-language progress such as "The document ... is currently being processed." Once processing finishes, a query call like agent.chat("tell me about cogniswitch") returns an answer synthesized from the stored content; document status can also be checked directly in the CogniSwitch console instead of through the agent.
Who it's for
Developers building LlamaIndex agents that need a managed knowledge-ingestion and retrieval layer -- storing documents or URLs, tracking their processing status, and answering questions against them -- without building their own vector store and retrieval pipeline.
Source README
Cogniswitch ToolSpec
Use CogniSwitch to build production ready applications that can consume, organize and retrieve knowledge flawlessly. Using the framework of your choice, in this case LlamaIndex, CogniSwitch helps alleviate the stress of decision making when it comes to, choosing the right storage and retrieval formats. It also eradicates reliability issues and hallucinations when it comes to responses that are generated. Get started by interacting with your knowledge in just three simple steps
visit https://www.cogniswitch.ai/developer.
Registration:
- Signup with your email and verify your registration
- You will get a mail with a platform token and OAuth token for using the services.
Step 1: Instantiate the Cogniswitch ToolSpec:
- Use your Cogniswitch token, openAI API key, OAuth token to instantiate the toolspec.
Step 2: Instantiate the Agent:
- Instantiate the agent with the list of tools from the toolspec.
Step 3: Cogniswitch Store data:
- Make the call to the agent by giving the file path or url to the agent input.
- The agent will pick the tool and use the file/url and it will be processed and stored in your knowledge store.
- You can check the status of document processing with a call to the agent. Alternatively you can also check in [cogniswitch console](- You can check the status of document processing with a call to the agent. Alternatively you can also check in cogniswitch console.
Step 4: Cogniswitch Answer:
- Make the call to the agent by giving query as agent input.
- You will get the answer from your knowledge as the response.
Import Required Libraries
import warnings
warnings.filterwarnings("ignore")
import os
from llama_index.tools.cogniswitch import CogniswitchToolSpec
from llama_index.core.agent import ReActAgent
Cogniswitch Credentials and OpenAI token
### os.environ["OPENAI_API_KEY"] = <your openai token>
### cs_token = <your cogniswitch platform token>
### oauth_token = <your cogniswitch apikey>
Instantiate the Tool Spec
toolspec = CogniswitchToolSpec(cs_token=cs_token, apiKey=oauth_token)
Get the list of tools
tool_lst = toolspec.to_tool_list()
Instantiate the agent with the tool list
agent = ReActAgent.from_tools(tool_lst)
Use the agent for storing data in cogniswitch with a single call
store_response = agent.chat(
"""
https://cogniswitch.ai/developer
this site is about cogniswitch website for developers.
"""
)
print(store_response)
{'data': {'knowledgeSourceId': 43, 'sourceType': 'https://cogniswitch.ai/developer', 'sourceURL': None, 'sourceFileName': None, 'sourceName': 'Cogniswitch dev', 'sourceDescription': 'This is a cogniswitch website for developers.', 'status': 'UPLOADED'}, 'list': None, 'message': "We're processing your content & will send you an email on completion, hang tight!", 'statusCode': 1000}
Use the agent to know the document status with a single call
response = agent.chat("Tell me the status of Cogniswitch Developer Website")
print(response)
The document "Cogniswitch Developer Website" is currently being processed.
Use the agent for answering a query with a single call
answer_response = agent.chat("tell me about cogniswitch")
print(answer_response)
{'data': {'answer': 'CogniSwitch is a technology platform that enhances the reliability of Generative AI applications for enterprises. It does this by gathering and organizing knowledge from documented sources, eliminating hallucinations and bias in AI responses. The platform uses AI to automatically gather and organize knowledge
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.