relevanceai.utils.doc_utils.doc_utils#

Module Contents#

class relevanceai.utils.doc_utils.doc_utils.DocUtils#

Class for all document utilities. Primarily should be used as a mixin for future functions but can be a standalone. # TODO: Extend to Chunk Doc Reading and Chunk Doc Writing

class relevanceai.utils.doc_utils.doc_utils.Document(document: Dict)#

Class for all document utilities. Primarily should be used as a mixin for future functions but can be a standalone. # TODO: Extend to Chunk Doc Reading and Chunk Doc Writing

setitem(self, obj, keys: List[str], value: Any) None#

> It takes a list of keys, and a value, and sets the value at the end of the list of keys

Parameters
  • obj – The object to set the value on.

  • keys (List[str]) – List[str]

  • value (Any) – The value to set.

json(self)#

If the value is a DataFrame, then call the json() function on it. Otherwise, if the value is a NaN, then return None. Otherwise, return the value

Return type

A dictionary of dictionaries.

keys(self, parent=None)#

It takes a dictionary, and returns a list of all the keys in the dictionary, including nested keys

Parameters

parent – The parent key of the current dictionary.

Return type

A list of keys

get(self, key, value=None)#

If the key is in the dictionary, return the value, otherwise return the default value

Parameters
  • key – The key to be searched in the dictionary

  • value – The value to return if the key is not found. If not specified, None is returned.

Return type

The value of the key.

values(self)#

It takes the dictionary, enumerates the keys, and then creates a new dictionary with the enumerated keys as the keys and the values as the values. Then it returns the values of the new dictionary

Return type

The values of the dictionary.

items(self)#

It returns a list of tuples, where each tuple is a key-value pair

Return type

A dictionary of the keys and values of the class.

update(self, other: Dict[str, Any])#

If the value is a dictionary, then create a new Document object with the value as the data. Otherwise, just set the value

Parameters

other (Dict[str, Any]) – Dict[str, Any]

class relevanceai.utils.doc_utils.doc_utils.DocumentList(documents: List)#

A Class for handling json like arrays of dictionaries

Example: >>> docs = DocumentList([{“value”: 2}, {“value”: 10}])

insert(self, index, document)#

It takes a document and inserts it into the list of documents at the specified index

Parameters
  • index – The index of the element before which to insert the new element.

  • document – The document to insert.

json(self)#

It returns a list of json objects.

Return type

A list of dictionaries.