Skip to content

Data Classes

All public methods on LocalLens return one of these dataclasses. Each has a to_dict() method for JSON serialization.

python
from locallens import IndexResult, SearchResult, AskResult, StatsResult, FileInfo, DoctorCheck

IndexResult

Returned by LocalLens.index().

FieldTypeDescription
total_filesintTotal files in index
new_filesintNewly indexed files
updated_filesintRe-indexed files
skipped_filesintSkipped (unchanged) files
total_chunksintTotal chunks in index
duration_secondsfloatTime taken
json
{
  "total_files": 42,
  "new_files": 5,
  "updated_files": 2,
  "skipped_files": 35,
  "total_chunks": 1284,
  "duration_seconds": 3.47
}

SearchResult

Returned by LocalLens.search() (as a list).

FieldTypeDescription
file_pathstrAbsolute path to the file
file_namestrFile name only
file_typestrFile extension (e.g. .pdf)
chunk_textstrThe matched text chunk
chunk_indexintChunk position within the file
scorefloatRelevance score
extractorstr | NoneExtractor that produced this chunk
json
{
  "file_path": "/Users/me/Documents/report.pdf",
  "file_name": "report.pdf",
  "file_type": ".pdf",
  "chunk_text": "Q3 revenue exceeded projections by 12%...",
  "chunk_index": 3,
  "score": 0.8742,
  "extractor": "pymupdf"
}

AskResult

Returned by LocalLens.ask().

FieldTypeDescription
answerstrThe generated answer
sourceslist[SearchResult]Source chunks used for context
modelstrOllama model used
duration_secondsfloatTime taken
json
{
  "answer": "Q3 revenue was $4.2M, exceeding projections by 12%.",
  "sources": [
    {
      "file_path": "/Users/me/Documents/report.pdf",
      "file_name": "report.pdf",
      "file_type": ".pdf",
      "chunk_text": "Q3 revenue exceeded projections...",
      "chunk_index": 3,
      "score": 0.8742,
      "extractor": "pymupdf"
    }
  ],
  "model": "qwen2.5:3b",
  "duration_seconds": 5.23
}

AskStreamEvent

Yielded by LocalLens.ask_stream().

FieldTypeDescription
event_typestr"token" or "sources"
dataAnyToken string or list of SearchResult

When event_type is "token", data is a string (one token of the answer). When event_type is "sources", data is a list[SearchResult] with the context chunks.

StatsResult

Returned by LocalLens.stats().

FieldTypeDescription
total_filesintNumber of indexed files
total_chunksintNumber of chunks
file_typesdict[str, int]Chunk count per file type
collection_namestrQdrant collection name
data_dirstrData directory path
json
{
  "total_files": 42,
  "total_chunks": 1284,
  "file_types": {
    ".pdf": 450,
    ".py": 320,
    ".md": 280,
    ".txt": 234
  },
  "collection_name": "locallens",
  "data_dir": "/Users/me/.locallens"
}

FileInfo

Returned by LocalLens.files() (as a list).

FieldTypeDescription
file_pathstrAbsolute path
file_namestrFile name
file_typestrFile extension
chunk_countintNumber of chunks
indexed_atstr | NoneISO timestamp
json
{
  "file_path": "/Users/me/Documents/report.pdf",
  "file_name": "report.pdf",
  "file_type": ".pdf",
  "chunk_count": 15,
  "indexed_at": "2024-12-15T10:30:00Z"
}

DoctorCheck

Returned by LocalLens.doctor() (as a list).

FieldTypeDescription
namestrCheck name
statusstr"ok", "fail", or "warn"
messagestrDetail message
json
{
  "name": "Qdrant Edge",
  "status": "ok",
  "message": "1284 points in shard"
}

Released under the MIT License.