relevanceai.utils.doc_utils.write_utils#

Module Contents#

class relevanceai.utils.doc_utils.write_utils.DocWriteUtils#

This is created as a Mixin for others to easily add to their classes

run_function_against_all_documents(self, fn, docs, field=None)#

Run a function against documetns if the field is there

set_fields_across_document(self, fields: List[str], doc: Dict, values: List)#
static set_field(field: str, doc: Dict, value: Any, handle_if_missing=True, inplace=True)#

For nested dictionaries, tries to write to the respective field. If you toggle off handle_if_misisng, then it will output errors if the field is not found. e.g. field = kfc.item value = “fried wings” This should then create the following entries if they dont exist: {

“kfc”: {

“item”: “fried wings”

}

} :param field: Field of the document to write. :param doc: Python dictionary :param value: Value to write

Example

>>> from vectorai.client import ViClient
>>> vi_client = ViClient(username, api_key, vectorai_url)
>>> sample_document = {'kfc': {'item': ''}}
>>> vi_client.set_field('kfc.item', sample_document, 'chickens')
set_field_across_documents(self, field: str, values: List[Any], docs: List[Dict])#

For multiple documents, set the right fields. e.g. field = kfc.item value = “fried wings” This should then create the following entries if they dont exist: {

“kfc”: {

“item”: “fried wings”

}

} :param field: Field of the document to write. :param doc: Python dictionary :param value: Value to write

Example

>>> from vectorai.client import ViClient
>>> vi_client = ViClient(username, api_key, vectorai_url)
>>> sample_document = {'kfc': {'item': ''}}
>>> vi_client.set_fields('kfc.item', sample_document, 'chickens')