themisim.SearchEngine

class themisim.SearchEngine(artifacts_dir, *, index_filename='index.faiss', manifest_filename='manifest.parquet', memmap_filename='vectors.f16.dat', meta_filename='vectors.meta.json', brute_force_max=4000000)[source]

Loads the index + manifest + memmap once; serves many queries.

Construction is moderately expensive (faiss.read_index can take a few seconds on a large index, manifest deserialization a similar amount). Hold one engine instance per process. In Streamlit, wrap with st.cache_resource.

Parameters:
  • artifacts_dir (Union[str, Path])

  • index_filename (str)

  • manifest_filename (str)

  • memmap_filename (str)

  • meta_filename (str)

  • brute_force_max (int)

__init__(artifacts_dir, *, index_filename='index.faiss', manifest_filename='manifest.parquet', memmap_filename='vectors.f16.dat', meta_filename='vectors.meta.json', brute_force_max=4000000)[source]
Parameters:
  • artifacts_dir (str | Path)

  • index_filename (str)

  • manifest_filename (str)

  • memmap_filename (str)

  • meta_filename (str)

  • brute_force_max (int)

Return type:

None

Methods

__init__(artifacts_dir, *[, index_filename, ...])

frame_idx_of(gid)

Row index of this global_id's frame inside its shard.

search(query_vec, *[, k, min_score, ...])

Return Hits ranked best first, temporally diversified.

shard_of(gid)

Absolute path of the .f16.npy shard holding this global_id's frame.

shard_starts()

Global_ids where a new shard/CDF begins, with a terminal total_n sentinel appended.

site_of(gid)

Site code (e.g. 'fsmi') for a global_id.

sites()

All distinct site codes present, sorted.

time_ns_bounds()

(min, max) frame timestamp in ns — the indexed UTC time span.

time_ns_of(gid)

UTC timestamp (ns since the epoch) of this global_id's frame.