Train PandasAI
You can train PandasAI to understand your data better and to improve its performance. Training is as easy as calling the train
method on the Agent
.
There are two kinds of training:
- instructions training
- q/a training
Prerequisites
Before you start training PandasAI, you need to set your PandasAI API key. You can generate your API key by signing up at https://pandabi.ai.
Then you can set your API key as an environment variable:
It is important that you set the API key, or it will fail with the following error: No vector store provided. Please provide a vector store to train the agent
.
Instructions training
Instructions training is used to teach PandasAI how you expect it to respond to certain queries. You can provide generic instructions about how you expect the model to approach certain types of queries, and PandasAI will use these instructions to generate responses to similar queries.
For example, you might want the LLM to be aware that your company’s fiscal year starts in April, or about specific ways you want to handle missing data. Or you might want to teach it about specific business rules or data analysis best practices that are specific to your organization.
To train PandasAI with instructions, you can use the train
method on the Agent
, as it follows:
The training uses by default the BambooVectorStore
to store the training data, and it’s accessible with the API key.
As an alternative, if you want to use a local vector store (enterprise only for production use cases), you can use the ChromaDB
, Qdrant
or Pinecone
vector stores (see examples below).
Your training data is persisted, so you only need to train the model once.
Q/A training
Q/A training is used to teach PandasAI the desired process to answer specific questions, enhancing the model’s performance and determinism. One of the biggest challenges with LLMs is that they are not deterministic, meaning that the same question can produce different answers at different times. Q/A training can help to mitigate this issue.
To train PandasAI with Q/A, you can use the train
method on the Agent
, as it follows:
Also in this case, your training data is persisted, so you only need to train the model once.
Training with local Vector stores
If you want to train the model with a local vector store, you can use the local ChromaDB
, Qdrant
or Pinecone
vector stores. Here’s how to do it:
An enterprise license is required for using the vector stores locally, (check it out).
If you plan to use it in production, contact us.
Troubleshooting
In some cases, you might get an error like this: No vector store provided. Please provide a vector store to train the agent
. It means no API key has been generated to use the BambooVectorStore
.
Here’s how to fix it:
First of all, you’ll need to generated an API key (check the prerequisites paragraph above). Once you have generated the API key, you have 2 options:
- Override the env variable (
os.environ["PANDASAI_API_KEY"] = "YOUR_PANDASAI_API_KEY"
) - Instantiate the vector store and pass the API key:
Was this page helpful?