Inserting data

Guide on how to insert data into RelevanceAI

Inserting the data

Your data should be in the form of a list of dictionaries, each dictionary representing one document.

from relevanceai import Client

client = Client(token=YOUR_ACTIVATION_TOKEN)

documents = [
  {"_id": "1", "text": "Apple IPhone 13 Pro"},
  {"_id": "2", "text": "Fresh Apple"}

ds = client.Dataset("example")


If you don't have a unique "_id" for each document. Use create_id=True.

ds.insert_documents(documents, create_id=True)

With Relevance you don't have to specify the schema or field types of your data. It will automatically be detected, to see all the different field types and how to overwrite it on insert. Check out Dataset schema.

To avoid overwrite, make overwrite=False.

ds.insert_documents(documents, overwrite=False)

Update documents

To only update specific documents, use upsert_documents as shown in the example below:

ds.upsert_documents(documents=[{"_id": "2", "text": "Fresh Green Apple"}])


When To Use Upsert Vs Insert

insert replaces the entire document whereas upsert only changes the fields that are specified or newly added. It will not delete fields that are already in the dataset, nor insert new documents.

Inserting Pandas Dataframe