Python API¶
The reference for the completr package, generated from its typed stubs
(__init__.pyi).
Every name on this page is importable from completr.
Connecting¶
connect
¶
connect(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
**build_options,
) -> Database
Opens the database at url: a local path, or an s3://, gs://, az:// or memory:// URL.
connect takes the same arguments as Database: url, options, cache_dir, and
the keyword-only build options min_word_chars, max_edit_distance, fuzzy_prefix_chars, vector_bits,
compact_keys and build_threads.
connect_async
async
¶
connect_async(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
**build_options: Any,
) -> AsyncDatabase
Opens the database at url without blocking the event loop.
Documents¶
Document
¶
DocumentDict
¶
Bases: TypedDict
Documents
module-attribute
¶
Documents = Iterable[DocumentDict | Document] | Any
Dicts, Documents, or a pandas, polars or pyarrow table with those columns.
Vector
module-attribute
¶
An embedding: a 1-D float32 array or a list of floats.
Vectors
module-attribute
¶
One embedding row per document: a float32 array of shape (n, dim), or lists.
Suggestions¶
Suggestion
¶
highlights
instance-attribute
¶
(start, end) character offsets of text that matched the query.
HybridSuggestion
¶
AliasSuggestion
¶
MatchKind
module-attribute
¶
Segments, indexes and engines¶
Segment
¶
build
staticmethod
¶
build(
documents: Documents,
deletes: Sequence[Id] = ...,
vectors: Vectors | None = None,
*,
min_word_chars: int = 3,
max_edit_distance: int = 2,
fuzzy_prefix_chars: int = 7,
vector_bits: int = 4,
compact_keys: bool = False,
build_threads: int = 1,
path: str | PathLike[str] | None = None,
) -> Segment
Index
¶
Index(
segments: Sequence[Segment],
*,
max_score: float | None = None,
popularity_weight: float = 0.4,
short_query_chars: int = 3,
short_query_limit: int = 100,
short_query_cache_entries: int = 10000,
vector_threads: int = 1,
)
from_documents
staticmethod
¶
from_documents(
documents: Documents,
vectors: Vectors | None = None,
*,
max_score: float | None = None,
popularity_weight: float = 0.4,
min_word_chars: int = 3,
max_edit_distance: int = 2,
fuzzy_prefix_chars: int = 7,
vector_bits: int = 4,
build_threads: int = 1,
) -> Index
complete
¶
complete(
query: str,
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[Suggestion]
complete_aliases
¶
complete_aliases(
query: str,
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[AliasSuggestion]
vector_search
¶
vector_search(
vector: Vector,
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[Suggestion]
hybrid_search
¶
hybrid_search(
text: str,
vector: Vector,
limit: int = 10,
*,
fusion: FusionKind = "rrf",
rrf_k: float = 60.0,
semantic_weight: float = 0.5,
candidates: int | None = None,
contexts: Sequence[str] | None = None,
) -> list[HybridSuggestion]
Engine
¶
sync
¶
Loads the database's latest version; only for engines from Database.engine().
complete
¶
complete(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[Suggestion]
complete_aliases
¶
complete_aliases(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[AliasSuggestion]
vector_search
¶
vector_search(
vector: Vector,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
) -> list[Suggestion]
hybrid_search
¶
hybrid_search(
text: str,
vector: Vector,
layers: Sequence[str],
limit: int = 10,
*,
fusion: FusionKind = "rrf",
rrf_k: float = 60.0,
semantic_weight: float = 0.5,
candidates: int | None = None,
contexts: Sequence[str] | None = None,
) -> list[HybridSuggestion]
Databases¶
Database
¶
Database(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
*,
min_word_chars: int = 3,
max_edit_distance: int = 2,
fuzzy_prefix_chars: int = 7,
vector_bits: int = 4,
compact_keys: bool = False,
build_threads: int = 1,
)
open_index
¶
open_index(
name: str,
version: int | None = None,
*,
max_score: float | None = None,
popularity_weight: float = 0.4,
short_query_chars: int = 3,
short_query_limit: int = 100,
short_query_cache_entries: int = 10000,
vector_threads: int = 1,
) -> Index
engine
¶
engine(
*,
group_separator: str | None = None,
overfetch: int = 2,
popularity_weight: float = 0.4,
short_query_chars: int = 3,
short_query_limit: int = 100,
short_query_cache_entries: int = 10000,
vector_threads: int = 1,
) -> Engine
compact
¶
compact(
index: str,
*,
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
until_done: bool = False,
) -> int | None
cleanup
¶
Transaction
¶
ChangeSet
¶
Ingestor
¶
Ingestor(
database: Database,
owner: str,
*,
lease_ttl_seconds: float = 30.0,
max_change_sets: int = 1000,
compact: bool = True,
)
Replica
¶
Lease
¶
Store
¶
Store(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
)
asyncio¶
AsyncDatabase
¶
A Database whose storage operations are awaitable.
AsyncEngine
¶
An Engine that follows a database, with sync() awaitable.
Errors¶
Every error derives from CompletrError. NotFoundError is also a LookupError, InvalidInputError a
ValueError, and StorageError an OSError.
CompletrError
¶
Bases: Exception
Base class of every completr error.
ConflictError
¶
Bases: CompletrError
A concurrent commit changed what this transaction depends on.
CorruptionError
¶
Bases: CompletrError
Stored data failed its checksum or structural validation.
NotFoundError
¶
Bases: CompletrError, LookupError
A requested object, version or index does not exist.
InvalidInputError
¶
Bases: CompletrError, ValueError
An argument or document was invalid.
StorageError
¶
Bases: CompletrError, OSError
The file system or object store failed.