In Rivalz, Knowledge is a collection of documents. A knowledge base can be integrated into an application as a retrieval context.
How to create your first knowledge base
1. Prerequisites
Saving vector data can be an expensive process, so credits are required to create a knowledge base. However, we’ve got you covered! When you create an account, you’ll receive 500 USD in free credits. Visit here to learn How to claim your free credit.
Select the document you need to upload in PDF format.
API secret key to authenticate. If you don't have one, please refer to the "Get API Secret key" section to obtain it.
2. Setup the SDK
To install the SDK, run the following command for your preferred language:
Python
pip install rivalz-client
Nodejs
npm install rivalz-client
3. Initialize the client
To initialize the client with your secret token, you have two options:
Using a.env file with SECRET_TOKEN variable
you can pass the secret token directly to the client during initialization
Python: Use the python-dotenv package to load the token from .env file
from dotenv import load_dotenvfrom rivalz_client.client import RivalzClientload_dotenv()# Get the secret token from environment variablessecret_token = os.getenv('SECRET_TOKEN')ifnot secret_token:raiseValueError("SECRET_TOKEN is not set in the environment variables.")# Initialize the RivalzClient with the secret tokenclient =RivalzClient(secret_token)
Nodejs: Use the dotenv package to load the token from .env file
Use the create_rag_knowledge_base method to create a knowledge base. This method takes the path to the PDF document and the name of the knowledge base as arguments.
# python# create knowledge baseknowledge_base = client.create_rag_knowledge_base('sample.pdf', 'knowledge_base_name')print(knowledge_base)# print the knowledge base details
// node.js// create knowledge baseconstknowledgeBase=awaitrivalzClient.createRagKnowledgeBase('sample.pdf','knowledge_base_name');console.log(knowledgeBase); // print the knowledge base details
This method will return the knowledge base details as a JSON object, including the unique knowledge baseID. You can use this ID for future queries on the knowledge base.
The embedding process may take some time depending on the size of the document. This process will be processed off request and you can check when the process is done by checking the status of the knowledge base.
knowledge_base = client.create_rag_knowledge_base('sample.pdf', 'knowledge_base_name')print(knowledge_base)# you will get the knowledge base id with the status 'processing'# check the status of the knowledge baseknowledge_base = client.get_knowledge_base(knowledge_base['id'])print(knowledge_base['status'])# you will get 'ready' when the process is done
// node.jsconstknowledgeBase=awaitrivalzClient.createRagKnowledgeBase('sample.pdf','knowledge_base_name');console.log(knowledgeBase); // print the knowledge base details at this point the status will be 'processing'// check the status of the knowledge baseconstknowledgeBaseStatus=awaitrivalzClient.getKnowledgeBase(knowledgeBase.id);console.log(knowledgeBaseStatus.status); // you will get 'ready' when the process is done
Full code example
Python
# main.pyimport osfrom dotenv import load_dotenvfrom rivalz_client.client import RivalzClientimport timedefmain():# Load environment variables from .env fileload_dotenv()# Get the secret token from environment variables secret_token = os.getenv('SECRET_TOKEN')ifnot secret_token:raiseValueError("SECRET_TOKEN is not set in the environment variables.")# Initialize the RivalzClient with the secret token client =RivalzClient(secret_token)# create knowledge base knowledge_base = client.create_rag_knowledge_base('sample.pdf', 'knowledge_base_name')print(knowledge_base)# print the knowledge base details#sleep for 5 seconds to allow the process to finish you can do this in a loop time.sleep(5)# check the status of the knowledge base knowledge_base = client.get_knowledge_base(knowledge_base['id'])print(knowledge_base['status'])# you will get 'ready' when the process is doneif__name__=='__main__':main()
Nodejs
// main.jsimport RivalzClient from'rivalz-client';import dotenv from'dotenv';dotenv.config();asyncfunctionmain() {constrivalzClient=newRivalzClient(process.env.SECRET_TOKEN);constknowledgeBase=awaitrivalzClient.createRagKnowledgeBase('sample.pdf','knowledge_base_name');console.log(knowledgeBase); // print the knowledge base details// sleep for 5 seconds to allow the process to finish you can do this in a loopawaitnewPromise(resolve =>setTimeout(resolve,5000));// check the status of the knowledge baseconstknowledgeBaseStatus=awaitrivalzClient.getKnowledgeBase(knowledgeBase.id);}main();
Congratulations! You have successfully created your first knowledge base.