Index

An index is a near-realtime updateable data structure with full CRUD functionality.

from keyvi.index import Index
from keyvi.index import ReadOnlyIndex

index = Index("/tmp/index-directory")
index.set("a", '{"b": 3}')
index.flush()

ri = ReadOnlyIndex("/tmp/index-directory")
class keyvi.index.Index

A mutable keyvi index that supports reading, writing and deleting key-value pairs. The index is stored on disk and supports concurrent reads. Background merges are performed automatically to compact the index and optimize reads.

bulk_set(self: keyvi._core.index.Index, key_values: collections.abc.Sequence[tuple[str, str]]) → None

Set multiple key-value pairs in the index in a single batch.

delete(self: keyvi._core.index.Index, key: str) → None

Delete a key from the index.

flush(self: keyvi._core.index.Index, async: bool = False) → None

Flush pending writes to disk. If async is True, return immediately.

get(self: keyvi._core.index.Index, key: str, default: object = None) → object

Return the value for key if key is in the dictionary, else default.

get_fuzzy(self: keyvi._core.index.Index, key: str, max_edit_distance: SupportsInt | SupportsIndex, minimum_exact_prefix: SupportsInt | SupportsIndex = 2) → collections.abc.Iterator[keyvi._core.Match]

Fuzzy match for a key allowing up to max_edit_distance Levenshtein distance.

get_near(self: keyvi._core.index.Index, key: str, minimum_prefix_length: SupportsInt | SupportsIndex, greedy: bool = False) → collections.abc.Iterator[keyvi._core.Match]

Match a key near: match as much as possible exact given the minimum prefix length and then return everything below.

If greedy is True it matches everything below the minimum_prefix_length, but in the order of exact first.

set(self: keyvi._core.index.Index, key: str, value: str) → None

Set a key-value pair in the index.

class keyvi.index.ReadOnlyIndex

A read-only keyvi index for lookups without write or delete support. Useful for serving an index that is built and updated externally.

get(self: keyvi._core.index.ReadOnlyIndex, key: str, default: object = None) → object

Return the value for key if key is in the dictionary, else default.

get_fuzzy(self: keyvi._core.index.ReadOnlyIndex, key: str, max_edit_distance: SupportsInt | SupportsIndex, minimum_exact_prefix: SupportsInt | SupportsIndex = 2) → collections.abc.Iterator[keyvi._core.Match]

Fuzzy match for a key allowing up to max_edit_distance Levenshtein distance.

get_near(self: keyvi._core.index.ReadOnlyIndex, key: str, minimum_prefix_length: SupportsInt | SupportsIndex, greedy: bool = False) → collections.abc.Iterator[keyvi._core.Match]

Match a key near: match as much as possible exact given the minimum prefix length and then return everything below.

If greedy is True it matches everything below the minimum_prefix_length, but in the order of exact first.