relevanceai.api.batch.mongo_to_relevance_ai

Migrate from mongo database to Relevance Ai:

#Create an object of Mongo2RelevanceAi class connection_string= “…” project= “…” api_key= “…” mongo2vec = Mongo2Mongo2RelevanceAi(connection_string, project, api_key)

#Get a summary of the mondo database using “mongo_summary” mongo2vec.mongo_summary()

#Set the desired source mongo collection using “set_mongo_collection” db_name = ‘…’ collection_name = ‘…’ mongo2vec.set_mongo_collection(db_name, collection_name)

#Get total number of entries in the mongo collection using “mongo_doc_count” doc_cnt = mongo2vec.mongo_doc_count()

#Migrate data from mongo to Relevance Ai using “migrate_mongo2relevance_ai” chunk_size = 5000 # migrate batches of 5000 (default 2000) start_idx= 12000 # loads from mongo starting at index 12000 (default 0) dataset_id = “…” # dataset id in the Relevance Ai platform mongo2vec.migrate_mongo2relevance_ai(dataset_id, doc_cnt, chunk_size = chunk_size, start_idx= start_idx)

Module Contents

Classes

Mongo2RelevanceAi

Batch API client

Attributes

PYMONGO_AVAILABLE

BSON_AVAILABLE

relevanceai.api.batch.mongo_to_relevance_ai.PYMONGO_AVAILABLE = True
relevanceai.api.batch.mongo_to_relevance_ai.BSON_AVAILABLE = True
class relevanceai.api.batch.mongo_to_relevance_ai.Mongo2RelevanceAi(connection_string: str, project: str, api_key: str)

Bases: relevanceai.api.client.BatchAPIClient

Batch API client

mongo_summary(self)

returns a dictionary {key:value} key = db names value = collection names in each db

get_mongo_db(self, db_name: str)
get_mongo_collection(self, db_name: str, collection_name: str)
set_mongo_db(self, db_name: str)
set_mongo_collection(self, db_name: str, collection_name: str)
mongo_doc_count(self)
create_relevance_ai_dataset(self, dataset_id: str)
update_id(self, docs: List[dict])
static parse_json(data)
static flatten_inner_indxs(docs: List[dict])
static remove_nan(docs: List[dict], replace_with: str = '')
static build_range(doc_cnt: int, chunk_size: int = 2000, start_idx: int = 0)
fetch_mongo_collection_data(self, start_idx: int = None, end_idx: int = None)
migrate_mongo2relevance_ai(self, dataset_id: str, doc_cnt: int, chunk_size: int = 2000, start_idx: int = 0, overwite: bool = False)