Update Record
Update Record in Text Collection
To update an existing record, use the update_record
method. This method requires the following parameters:
collection_id
: The identifier of the collection where the record is stored.record_id
: The identifier of the record to be updated.content
: (Optional) The new textual content of the record.type
: (Optional) The type of record. Supported types aretext
,web
, andfile
.url
: (Optional) The URL of the webpage to be scraped.file_id
: (Optional) The file ID of the record to be updated.text_splitter
: (Optional) A dictionary containing the text splitter configuration.metadata
: (Optional) A dictionary containing metadata for the record.
Ensure that the combination of content
, type
, url
, and file_id
is valid. Specify the type
and set a value for one of content
, url
, or file_id
parameters that match the type.
Example of Updating a Record with New Content:
import taskingai
record = taskingai.retrieval.update_record(
collection_id="YOUR_COLLECTION_ID",
record_id="YOUR_RECORD_ID",
type="text",
content="Machine learning is a subfield of artificial intelligence...",
text_splitter={"type": "token", "chunk_size": 200, "chunk_overlap": 20},
)
After updating the content, all the old text chunks associated with the record will be deleted and replaced with the new ones.
Example of Updating Metadata:
import taskingai
record = taskingai.retrieval.update_record(
collection_id="YOUR_COLLECTION_ID",
record_id="YOUR_RECORD_ID",
metadata={"file_name": "machine_learning.pdf", "author": "James Brown"}
)
Update Record in QA Collection
To update an existing record, use the update_record
method. The related parameters are as follows:
collection_id
: The identifier of the collection where the record is stored.record_id
: The identifier of the record to be updated.type
: The type of record. It is alwaysqa_sheet
.file_id
: The file ID of the record to be updated.metadata
: The metadata of the record.
Example of Updating a Record with New Content:
import taskingai
new_file = taskingai.file.upload_file(file=open("PATH_TO_FILE", "rb"), purpose="qa_record_file")
print(f"Uploaded file ID: {new_file.file_id}")
record = taskingai.retrieval.update_record(
collection_id="YOUR_COLLECTION_ID",
record_id="YOUR_RECORD_ID",
type="qa_sheet",
file_id=new_file.file_id,
)
After updating the content, all the old Q&A chunks associated with the record will be deleted and replaced with the new ones.
Example of Updating Metadata:
import taskingai
record = taskingai.retrieval.update_record(
collection_id="YOUR_COLLECTION_ID",
record_id="YOUR_RECORD_ID",
metadata={"file_name": "new_product_qa_sheet.csv"},
)