class documentation

class FlatFileDB(qaapDB):

Constructor: FlatFileDB(root)

View In Hierarchy

Undocumented

Method __init__ Initializes a FlatFileDB instance (inherits from qAApDB), which manages data in text files using a structured folder hierarchy.
Method add_attribute_values Writes a new attribute to the <attribute>.txt file. If there is an error writing to the file, it raises a WriteInDatabaseError.
Method attribute_exists Checks if a attribute exists.
Method comment_exists Checks if a note for the specified document by the specified note_title exists.
Method get_all_documents_data Retrieves data from all public Document files.
Method get_attribute_values Retrieves the specified attribute values.
Method get_catalog Retrieves the catalog.
Method get_document Retrieves the content and icon of a specified document.
Method get_document_medias Retrieves the base64-encoded images for a specified document. Returns an empty list if there are no images.
Method get_note_medias Retrieves the base64-encoded images for a specified note of a document. Returns an empty list if there are no images.
Method get_notes_for_post Retrieves all notes for a specified document. If perpage is greater than 0, it returns only the notes for the specified page (0-indexed). If perpage less than 1, it returns all notes. Returns an empty list if there are no notes.
Method get_vector_store Retrieves the vector store as binary from a file.
Method post_exists Checks if a directory for the specified document exists.
Method write_attribute Writes new content in the <attributes>.txt file. If there is an error writing to the file, it raises a WriteInDatabaseError.
Method write_catalog Writes the catalog to a JSON file.
Method write_comment Writes a note for a specified document by a specified note_title. It creates a directory for the note, writes the note content to a text file, saves the note icon as a PNG file, and saves screenshots as PNG files...
Method write_post Writes a new document to the database. It creates a directory for the document, writes the document content to a text file, saves the icon as a PNG file, and saves screenshots as PNG files. If the document already exists, it raises a FileAlreadyExistsError...
Method write_vector_store Writes the binary representation of a vectorstore in a file.
Instance Variable root Undocumented
Method _setup_db_folder Initializes the required database folder structure and files.
def __init__(self, root: int):

Initializes a FlatFileDB instance (inherits from qAApDB), which manages data in text files using a structured folder hierarchy. Args: root (str): The root directory path where the folder hierarchy will be created. All data files and subdirectories will be stored under this path.

def add_attribute_values(self, attribute: str, data: list[str]) -> bool:

Writes a new attribute to the <attribute>.txt file. If there is an error writing to the file, it raises a WriteInDatabaseError. Args: attribute (str): Name of the attribute to write. data (str): The new attribute value to write. Returns: bool: True if the write operation was successful Raises: FileAlreadyExistsError: If the attribute already exists. WriteInDatabaseError: If there is an error writing to the file.

def attribute_exists(self, attribute: str) -> bool:

Checks if a attribute exists. Args: attribute (str): Name of the attribute to check. Returns: bool: True if the attribute exists, False otherwise. Raises: FileNotFoundError: If the <attribute>.txt file does not exist.

def comment_exists(self, post_title: str, note_title: str) -> bool:

Checks if a note for the specified document by the specified note_title exists. Args: post_title (str): Name of the document. note_title (str): Name of the note_title. Returns: bool: True if the note exists, False otherwise.

def get_all_documents_data(self) -> list[dict[str, str]]:

Retrieves data from all public Document files. This method scans the 'documents' directory for files named 'document.txt', reads their content, and compiles the data into a list of dictionaries. Each dictionary contains the content of a Document file and the Document name. Returns: list[dict[str,str]]: A list of dictionaries where each dictionary contains: - "page_content": The content of the document file. - "title": The name of the directory containing the document file. i.e. the document title

def get_attribute_values(self, attribute: str) -> str:

Retrieves the specified attribute values. Returns: str: The attribute name Raises: FileNotFoundError: If the <attribute>.txt file does not exist.

def get_catalog(self) -> str:

Retrieves the catalog. Returns: str: JSON string representing the catalog. Raises: FileNotFoundError: If the catalog.json file does not exist.

def get_document(self, post_title: str) -> tuple[str, str]:

Retrieves the content and icon of a specified document. Args: post_title (str): Name of the document to retrieve. Returns: tuple[str,str]: A tuple containing the document content (and the icon in base64 format if it exists or an empty string). Raises: FileNotFoundError: If the document does not exist or if the document.txt is missing.

def get_document_medias(self, post_title: str, includes: list[str] = None) -> list[str]:

Retrieves the base64-encoded images for a specified document. Returns an empty list if there are no images. Args: post_title (str): Name of the document. includes (list[str]): List of image file stems to include (e.g., ["screen1", "screen2"]). Returns: list[str]: A list of base64-encoded images for the document. Raises: FileNotFoundError: If the document does not exist.

def get_note_medias(self, post_title: str, note_title: str, includes: list[str] = None) -> list[str]:

Retrieves the base64-encoded images for a specified note of a document. Returns an empty list if there are no images. Args: post_title (str): Name of the document. note_title (str): Name of the note_title. includes (list[str]): List of image file stems to include (e.g., ["screen1", "screen2"]). Returns: list[str]: A list of base64-encoded images for the note. Raises: FileNotFoundError: If the note does not exist.

def get_notes_for_post(self, post_title: str, perpage: int = 0, page: int = 0) -> list[tuple[str, str, str]]:

Retrieves all notes for a specified document. If perpage is greater than 0, it returns only the notes for the specified page (0-indexed). If perpage less than 1, it returns all notes. Returns an empty list if there are no notes. Args: post_title (str): Name of the document to retrieve notes for. perpage (int): Number of notes per page. Default is 0 (all notes). page (int): Page number to retrieve (0-indexed). Default is 0. Returns: list[tuple[str,str,str]]: A list of tuples, each containing: - The note content as a string. - The note_title name as a string. - The document name as a string. Raises: FileNotFoundError: If the document does not exist or if there are no notes.

def get_vector_store(self) -> bytes:

Retrieves the vector store as binary from a file. Returns: bytes: The bytes representation of the vectorstore. Raises: FileNotFoundError: If the file is not found or any other exception occurs during the file read operation.

def post_exists(self, post_title: str) -> bool:

Checks if a directory for the specified document exists. Args: post_title (str): Name of the document to check. Returns: bool: True if the document exists, False otherwise.

def write_attribute(self, attribute: str, data: str) -> bool:

Writes new content in the <attributes>.txt file. If there is an error writing to the file, it raises a WriteInDatabaseError. Args: attribute (str): The attribute name data (str): The list of attributes to write. One attribute per line. Returns: bool: True if the write operation was successful Raises: WriteInDatabaseError: If there is an error writing to the file.

def write_catalog(self, json: str) -> bool:

Writes the catalog to a JSON file. Args: json (str): JSON string representing the catalog. Returns: bool: True if the write operation was successful Raises: WriteInDatabaseError: If there is an error writing to the file.

def write_comment(self, post_title: str, note_title: str, content: str, medias: list[str, str] = []) -> bool:

Writes a note for a specified document by a specified note_title. It creates a directory for the note, writes the note content to a text file, saves the note icon as a PNG file, and saves screenshots as PNG files. If the document does not exist, it raises a FileNotFoundError. If the note already exists, it raises a FileAlreadyExistsError. Args: post_title (str): Name of the document to write the note for. note_title (str): Name of the note_title. content (str): Content of the note. icon (str): Base64 encoded icon of the note. screenshots (list[str]): list of base64 encoded screenshots of the note. Returns: bool: True if the write operation was successful Raises: FileNotFoundError: If the document does not exist. FileAlreadyExistsError: If the note already exists. WriteInDatabaseError: If there is an error writing to the file or creating directories.

def write_post(self, post_title: str, content: str, icon: str = '', medias: list[str, str] = []) -> bool:

Writes a new document to the database. It creates a directory for the document, writes the document content to a text file, saves the icon as a PNG file, and saves screenshots as PNG files. If the document already exists, it raises a FileAlreadyExistsError. Args: post_title (str): Name of the document to write. content (str): Content of the document. icon (str): Base64 encoded icon of the document. screenshots (list[str]): list of base64 encoded screenshots of the document. Returns: bool: True if the write operation was successful Raises: FileAlreadyExistsError: If the document already exists. WriteInDatabaseError: If there is an error writing to the file or creating directories.

def write_vector_store(self, bytes: bytes) -> bool:

Writes the binary representation of a vectorstore in a file. Args: bytes: The bytes representation of the vectorstore. Returns: bool: True if the write operation is successful. Raises: WriteInDatabaseError: If any exception occurs during the file write operation.

root =

Undocumented

def _setup_db_folder(self):

Initializes the required database folder structure and files. Creates the following directories under `self.root` if they do not exist: - "rag" - "documents" - "summaries"