Python API¶
The reference for the completype package, generated from its typed stubs:
__init__.pyi,
completype.pyi
and _async.pyi.
Every name on this page is importable from completype.
Databases¶
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(url, ...) is Database(url, ...): it takes url, options, cache_dir and the build options
min_word_chars, max_edit_distance, fuzzy_prefix_chars, vector_bits, compact_keys and
build_threads. See Configuration.
Database
¶
Database(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
*,
tags: Mapping[str, 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,
)
namespace
¶
namespace(name: str) -> DatabaseNamespace
Namespace name: 1 to 128 letters, digits, '.', '_' or '-'. Does no I/O.
index_names
¶
Indexes of the default namespace.
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(
*,
sync_every: float | None = 5.0,
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
¶
DatabaseNamespace
¶
One namespace of a Database: its transactions, indexes and compaction.
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
compact
¶
compact(
index: str,
*,
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
until_done: bool = False,
) -> int | None
Transaction
¶
NamespaceTransaction
¶
Lease
¶
Store
¶
Store(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
*,
tags: Mapping[str, str] | None = None,
)
Indexes and engines¶
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]
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
SegmentWriter
¶
Engine
¶
sync_status
property
¶
The background sync's last run: synced_at and error; None before it has run.
sync
¶
Loads the database's latest version now; only for engines from Database.engine().
namespace
¶
namespace(name: str) -> Namespace
The current version of namespace name; NamespaceNotFoundError if there is none.
complete
¶
complete(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> list[Suggestion]
Namespace.complete in the default namespace.
complete_aliases
¶
complete_aliases(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> list[AliasSuggestion]
vector_search
¶
vector_search(
vector: Vector,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> 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,
ignore_missing_layers: bool = False,
) -> list[HybridSuggestion]
Namespace
¶
One version of one namespace; every search through it sees that version.
complete
¶
complete(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> list[Suggestion]
Later layers override earlier ones per document id; a missing layer raises LayerNotFoundError.
complete_aliases
¶
complete_aliases(
query: str,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> list[AliasSuggestion]
vector_search
¶
vector_search(
vector: Vector,
layers: Sequence[str],
limit: int = 10,
*,
contexts: Sequence[str] | None = None,
ignore_missing_layers: bool = False,
) -> 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,
ignore_missing_layers: bool = False,
) -> list[HybridSuggestion]
Replica
¶
Many writers¶
ChangeSet
¶
NamespaceChanges
¶
Ingestor
¶
Ingestor(
database: Database,
owner: str,
*,
lease_ttl_seconds: float = 30.0,
max_change_sets: int = 1000,
compact: bool = True,
)
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.
AliasSuggestion
¶
HybridSuggestion
¶
MatchKind
¶
Bases: StrEnum
How a suggestion matched its query. Members compare equal to their string values.
asyncio¶
AsyncDatabase
¶
AsyncDatabase(
url: str,
options: Mapping[str, str] | None = None,
cache_dir: str | PathLike[str] | None = None,
**build_options: Any,
)
Bases: _Lazy
A Database whose storage operations are awaitable: AsyncDatabase(url, ...) takes connect's arguments.
namespace
¶
namespace(name: str) -> AsyncDatabaseNamespace
Namespace name; storage opens on its first awaited call.
AsyncDatabaseNamespace
¶
AsyncDatabaseNamespace(database: AsyncDatabase, name: str)
A DatabaseNamespace whose storage operations are awaitable.
AsyncEngine
¶
AsyncEngine(engine: Engine)
An Engine whose sync() is awaitable; completions stay synchronous.
Errors¶
Every error derives from CompletypeError. NotFoundError is also a LookupError, InvalidInputError a
ValueError, and StorageError an OSError. NamespaceNotFoundError and LayerNotFoundError are
NotFoundErrors that carry the missing name and the names that exist in available.
CompletypeError
¶
Bases: Exception
ConflictError
¶
Bases: CompletypeError
CorruptionError
¶
Bases: CompletypeError
NotFoundError
¶
Bases: CompletypeError, LookupError
NamespaceNotFoundError
¶
Bases: NotFoundError
LayerNotFoundError
¶
Bases: NotFoundError
InvalidInputError
¶
Bases: CompletypeError, ValueError
StorageError
¶
Bases: CompletypeError, OSError
Collections¶
The collections layer.
Client
¶
Client(
url: str = "memory://",
*,
sync_every: float | None = 5.0,
cache_dir: str | PathLike[str] | None = None,
options: Mapping[str, str] | None = None,
tags: Mapping[str, 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,
)
create_collection
¶
create_collection(
name: str,
*,
optimize: OptimizeKind = "auto",
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
min_interval: float = 30.0,
) -> Collection
get_or_create_collection
¶
get_or_create_collection(
name: str,
*,
optimize: OptimizeKind = "auto",
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
min_interval: float = 30.0,
) -> Collection
ClientNamespace
¶
The collections of one namespace.
create_collection
¶
create_collection(
name: str,
*,
optimize: OptimizeKind = "auto",
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
min_interval: float = 30.0,
) -> Collection
get_or_create_collection
¶
get_or_create_collection(
name: str,
*,
optimize: OptimizeKind = "auto",
fanout: int = 4,
max_segments: int = 16,
max_hidden_fraction: float = 0.25,
min_interval: float = 30.0,
) -> Collection
Collection
¶
add
¶
Adds documents, replacing any with the same id; durable on return. Returns the new version.
complete
¶
complete(
query: str,
limit: int = 10,
*,
aliases: bool = False,
layers: Sequence[str] | None = None,
contexts: Sequence[str] | None = None,
vector: Vector | None = None,
ignore_missing_layers: bool = False,
) -> list[Suggestion]
Completions, best first; Suggestion.layer is the collection each came from.
CollectionStats
¶
Bases: TypedDict
AsyncClient
¶
Bases: _Lazy
A Client whose storage calls are awaitable: AsyncClient(url, ...) takes Client's arguments.
namespace
¶
namespace(name: str) -> AsyncClientNamespace
The collections of namespace name; storage opens on its first awaited call.
get_or_create_collection
async
¶
get_or_create_collection(
name: str, **settings: Any
) -> AsyncCollection
AsyncCollection
¶
AsyncCollection(collection: Collection)
A Collection whose writes and storage calls are awaitable; complete stays synchronous.
AsyncClientNamespace
¶
AsyncClientNamespace(client: AsyncClient, name: str)
A ClientNamespace whose storage calls are awaitable.
get_or_create_collection
async
¶
get_or_create_collection(
name: str, **settings: Any
) -> AsyncCollection