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_dotenv
from rivalz_client.client import RivalzClient
load_dotenv()
# Get the secret token from environment variables
secret_token = os.getenv('SECRET_TOKEN')
if not secret_token:
raise ValueError("SECRET_TOKEN is not set in the environment variables.")
# Initialize the RivalzClient with the secret token
client = RivalzClient(secret_token)
Nodejs: Use the dotenv package to load the token from .env file
import RivalzClient from 'rivalz-client';
import dotenv from 'dotenv';
dotenv.config();
const rivalzClient = new RivalzClient(process.env.SECRET_TOKEN);
4. Create a knowledge base
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 base
knowledge_base = client.create_rag_knowledge_base('sample.pdf', 'knowledge_base_name')
print(knowledge_base) # print the knowledge base details
// node.js
// create knowledge base
const knowledgeBase = await rivalzClient.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 base
knowledge_base = client.get_knowledge_base(knowledge_base['id'])
print(knowledge_base['status']) # you will get 'ready' when the process is done
// node.js
const knowledgeBase = await rivalzClient.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 base
const knowledgeBaseStatus = await rivalzClient.getKnowledgeBase(knowledgeBase.id);
console.log(knowledgeBaseStatus.status); // you will get 'ready' when the process is done
Full code example
Python
# main.py
import os
from dotenv import load_dotenv
from rivalz_client.client import RivalzClient
import time
def main():
# Load environment variables from .env file
load_dotenv()
# Get the secret token from environment variables
secret_token = os.getenv('SECRET_TOKEN')
if not secret_token:
raise ValueError("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 done
if __name__ == '__main__':
main()
Nodejs
// main.js
import RivalzClient from 'rivalz-client';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
const rivalzClient = new RivalzClient(process.env.SECRET_TOKEN);
const knowledgeBase = await rivalzClient.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 loop
await new Promise(resolve => setTimeout(resolve, 5000));
// check the status of the knowledge base
const knowledgeBaseStatus = await rivalzClient.getKnowledgeBase(knowledgeBase.id);
}
main();
Congratulations! You have successfully created your first knowledge base.