docsense.cli.main

Command Line Interface for DocSense.

This module provides the command-line interface for DocSense, offering three main commands: - index: Create a vector index from documents in a directory - ask: Ask a question and get an answer based on indexed documents - daemon: Run DocSense in daemon mode for faster consecutive queries

The CLI is built using Typer and Rich libraries for better user experience.

Functions

ask(question[, model_name, device, index_path])

Ask a question and get an answer based on indexed documents.

daemon([model_name, device, index_path])

Start DocSense in daemon mode for faster responses.

format_time(seconds)

Format time duration in a human-readable way.

index(path[, model_name, device, index_path])

Create document index from the specified path.

format_time(seconds)[source]

Format time duration in a human-readable way.

Parameters:

seconds (float) – Time duration in seconds

Return type:

str

Returns:

A formatted string showing minutes and seconds or just seconds if duration is less than a minute

index(path, model_name='Qwen/Qwen2-7B', device='cuda', index_path=PosixPath('/home/runner/.docsense/index'))[source]

Create document index from the specified path.

This command processes documents from the given directory and creates a vector index for semantic search capabilities.

Parameters:
  • path (Path) – Directory path containing documents to index

  • model_name (str) – Name of the embedding model to use

  • device (str) – Computing device to use (‘cuda’ or ‘cpu’)

  • index_path (Optional[Path]) – Path to save the generated index (uses default if not specified)

Raises:

typer.Exit – If an error occurs during indexing

ask(question, model_name='Qwen/Qwen2-7B', device='cuda', index_path=PosixPath('/home/runner/.docsense/index'))[source]

Ask a question and get an answer based on indexed documents.

This command processes a natural language question and returns an answer based on the content of indexed documents.

Parameters:
  • question (str) – The question to ask

  • model_name (str) – Name of the model to use for processing

  • device (str) – Computing device to use (‘cuda’ or ‘cpu’)

  • index_path (Optional[Path]) – Path to the document index (uses default if not specified)

Raises:

typer.Exit – If index is not found or an error occurs during processing

daemon(model_name='Qwen/Qwen2-7B', device='cuda', index_path=PosixPath('/home/runner/.docsense/index'))[source]

Start DocSense in daemon mode for faster responses.

This command starts an interactive session where the model stays loaded in memory, allowing for faster consecutive queries without reloading the model each time.

Parameters:
  • model_name (str) – Name of the model to use for processing

  • device (str) – Computing device to use (‘cuda’ or ‘cpu’)

  • index_path (Optional[Path]) – Path to the document index (uses default if not specified)

Raises:

typer.Exit – If an error occurs during daemon operation