imbed.imbed_project#
Project interface for text embedding system.
This module provides the core Project class that manages segments, embeddings, planarizations, and clusterings with automatic invalidation and async computation support via the au framework.
Module Attributes
The component kinds |
|
The subset of |
|
Which |
|
What |
|
|
|
Default reaction to a partial default input. |
|
How many missing segment keys an error/warning names before eliding the rest. |
Functions
|
|
|
Clear all items in a store |
|
Get the user stores for the package. |
|
Get the registry mall containing all function stores |
|
|
|
|
Assert the component-kind tables agree with each other. |
|
|
|
|
Classes
|
A mapping that allows retrieval of functions with optional partial application. |
|
Central project interface - facade for all operations. |
|
Container for projects with MutableMapping interface. |
- imbed.imbed_project.ASYNC_CAPABLE_COMPONENT_KINDS = frozenset({'embedder'})#
The subset of
COMPONENT_KINDSwhose work can be handed to the async (au) backend. Single source of truth on purpose:Project.compute()both resolves and validatesasync_modeagainst this one name, so the two cannot drift — and drift between them is exactly howasync_mode=Truecame to be silently downgraded to a synchronous run for the kinds the async branch did not cover.
- imbed.imbed_project.COMPONENT_KINDS = ('embedder', 'planarizer', 'clusterer')#
The component kinds
Project.compute()knows how to dispatch. Each namekindneeds aProject.{kind}sregistry attribute to resolve components from, and a way to store its results (seeRESULT_STORE_BY_COMPONENT_KIND).
- imbed.imbed_project.DFLT_ON_MISSING_EMBEDDINGS: Literal['raise', 'warn', 'ignore'] = 'warn'#
Default reaction to a partial default input.
"warn"rather than"raise"because “process what is ready” is a legitimate thing to want — pending embeddings are the normal state of an async project — but it must never be what a caller gets without knowing, since a result covering part of the project is indistinguishable from one covering all of it."raise"is one keyword away for all-or-nothing callers,"ignore"for those who already know the input is partial.
- imbed.imbed_project.MAX_MISSING_KEYS_SHOWN = 5#
How many missing segment keys an error/warning names before eliding the rest.
- imbed.imbed_project.MISSING_EMBEDDINGS_POLICIES = ('raise', 'warn', 'ignore')#
MissingEmbeddingsPolicy’s members, for runtime validation and messages.
- imbed.imbed_project.MissingEmbeddingsPolicy#
What
Project.compute()may do when the default planarizer/clusterer input it assembles is missing some segments (their embeddings have not landed yet).alias of
Literal[‘raise’, ‘warn’, ‘ignore’]
- class imbed.imbed_project.PartializedFuncs(store)[source]#
-
A mapping that allows retrieval of functions with optional partial application.
>>> store = {'add': lambda x, y: x + y, 'subtract': lambda x, y: x - y} >>> partialized_ops = PartializedFuncs(store)
When using a non-dict key, it will return the function directly:
>>> func1 = partialized_ops['add'] >>> func1(2, 3) 5
If the key is a dictionary with one item, it will return a partial function:
>>> func2 = partialized_ops[{'add': {'y': 3}}] >>> func2(2) 5
- class imbed.imbed_project.Project(segments=dict(), embeddings=dict(), planar_coords=dict(), cluster_indices=dict(), embedders=<factory>, planarizers=<factory>, clusterers=<factory>, default_embedder='default', _active_computations=dict(), _invalidation_cascade=True, _auto_compute_embeddings=True, _async_embeddings=False, _async_base_path=None, _id=None, _async_backend=None)[source]#
Bases:
objectCentral project interface - facade for all operations.
Manages segments, embeddings, planarizations, and clusterings with automatic computation and invalidation cascade. Supports both synchronous and asynchronous embedding computation via the au framework.
- compute(component_kind, component_key, data=None, *, save_key=None, async_mode=None, on_missing_embeddings='warn')[source]#
Generic computation dispatcher.
Runs the component the caller named, on the data the caller gave, in the mode the caller asked for — or raises saying why it cannot. It never quietly substitutes a different component, a different mode, or a different input: every path here returns the same kind of save key, so a silent substitution would be indistinguishable from success.
- Parameters:
component_kind (
str) – Type of component; one ofCOMPONENT_KINDS.component_key (
str) – Key of the component in the corresponding registry.data (
Mapping|Sequence|None) – Input data. If None, an appropriate default is used (see below). For an embedder it must be aMappingof segment key -> segment, since embeddings are stored per segment key and a bare sequence carries no keys to store them under.save_key (
str|None) – Key to file the results under. Generated (uniquely) if not given. An explicitly given key is honoured as given, and so overwrites any previous result stored under it.async_mode (
bool|None) – Whether to run asynchronously.None(the default) uses the project’s_async_embeddingssetting, which applies only to kinds inASYNC_CAPABLE_COMPONENT_KINDS. PassingTruefor any other kind raises: those kinds have no async path, and running them synchronously would silently contradict an explicit request.on_missing_embeddings (
Literal['raise','warn','ignore']) – What to do when the default input for a planarizer/clusterer is incomplete because some segments have no embedding yet — one ofMISSING_EMBEDDINGS_POLICIES, defaultDFLT_ON_MISSING_EMBEDDINGS. Only consulted whendatais None; when you supplydata, its completeness is yours to decide.
- Return type:
- Returns:
The save key. For a planarizer or clusterer this is the key its results are stored under, in
planar_coords/cluster_indicesrespectively. For an embedder it identifies the computation: embedding results are merged intoembeddingsunder their own segment keys, sync or async alike.
Default input by kind:
embedder: all of
segments.planarizer, clusterer: the embeddings of every segment that has one, in segment order (see
on_missing_embeddingsfor the ones that do not).
- How results are attributed to segments:
A component returning a mapping is taken at its word. A component returning a plain sequence is matched to its input by position — which requires knowing the input’s keys, so the sequence case is supported when
datawas defaulted or given as a mapping, and refused (rather than guessed) whendatawas given as a bare sequence.
- Raises:
ValueError – unknown
component_kind, unknowncomponent_key, async requested for a kind that cannot do it, an unknownon_missing_embeddings, or results that cannot be attributed to segments.TypeError – embedder
datathat is not a Mapping.
- Return type:
- property embedding_status: dict[str, int]#
Get counts of embedding statuses.
Returns counts of: present, missing, computing
- get_computation_status(computation_id)[source]#
Get status of a tracked async computation.
- Return type:
ComputationStatus|None
- class imbed.imbed_project.Projects(store_factory=<class 'dict'>)[source]#
Bases:
MutableMapping[str,Project]Container for projects with MutableMapping interface.
>>> projects = Projects() >>> p = Project(_id='test', segments={}, embeddings={}, ... planar_coords={}, cluster_indices={}, ... embedders={}, planarizers={}, clusterers={}) >>> projects["test"] = p >>> list(projects) ['test'] >>> projects["test"]._id 'test'
- create_project(*, project_id=None, segments_store_factory=<class 'dict'>, embeddings_store_factory=<class 'dict'>, planar_store_factory=<class 'dict'>, cluster_store_factory=<class 'dict'>, embedders=None, planarizers=None, clusterers=None, async_embeddings=True, async_base_path=None, async_backend=None, overwrite=False)[source]#
Create and add a new project.
- Parameters:
*_store_factory – Factory functions for various stores
embedders (
MutableMapping[str,Callable] |None) – Component registry for embeddersplanarizers (
MutableMapping[str,Callable] |None) – Component registry for planarizersclusterers (
MutableMapping[str,Callable] |None) – Component registry for clusterersasync_embeddings (
bool) – Whether to use async embedding computationasync_base_path (
str|None) – Base path for au async computation storageasync_backend (
Any|None) – Backend for async computation (StdLibQueueBackend, RQ, etc)overwrite (
bool) – If True, replace any existing project with the same id
- Return type:
- Returns:
The created Project instance
- imbed.imbed_project.RESULT_STORE_BY_COMPONENT_KIND = {'clusterer': 'cluster_indices', 'planarizer': 'planar_coords'}#
Which
Projectstore each component kind’s results are filed in, under the caller’ssave_key."embedder"is deliberately absent: embeddings are merged intoProject.embeddingsunder their segment keys, so an embedder’ssave_keynames the computation rather than a stored value.
- imbed.imbed_project.get_local_mall(project_id='default_project', *, mall_keys=('misc', 'segments', 'embeddings', 'clusters', 'planar_embeddings', 'statuses', 'cluster_labels'), default_store_maker=functools.partial(<function mk_blob_store_for_path>, path_to_bytes_store=<class 'dol.filesys.Files'>, base_store_wrap=functools.partial(<function extension_based_wrap>, extension_to_decoder={'csv': functools.partial(<function read_from_bytes>, functools.partial(<function read_csv>, index_col=None), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'txt': <method 'decode' of 'bytes' objects>, 'tsv': functools.partial(<function read_from_bytes>, functools.partial(<function read_csv>, sep='\t', index_col=None), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'parquet': functools.partial(<function read_from_bytes>, <function read_parquet>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'json': <function loads>, 'html': functools.partial(<function read_from_bytes>, functools.partial(<function read_html>, index_col=0), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'p': functools.partial(<function read_from_bytes>, <built-in function load>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'pickle': functools.partial(<function read_from_bytes>, <built-in function load>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'pkl': <built-in function loads>, 'xml': functools.partial(<function read_from_bytes>, <function read_xml>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'sql': functools.partial(<function read_from_bytes>, <function read_sql>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'sqlite': functools.partial(<function read_from_bytes>, <function read_sql>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'feather': functools.partial(<function read_from_bytes>, <function read_feather>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'stata': functools.partial(<function read_from_bytes>, functools.partial(<function read_stata>, index_col=0), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'dta': functools.partial(<function read_from_bytes>, functools.partial(<function read_stata>, index_col=0), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'sas': functools.partial(<function read_from_bytes>, <function read_sas>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'h5': functools.partial(<function read_from_bytes>, <function read_hdf>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'hdf5': functools.partial(<function read_from_bytes>, <function read_hdf>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'xls': functools.partial(<function read_from_bytes>, functools.partial(<function read_excel>, index_col=0), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'xlsx': functools.partial(<function read_from_bytes>, functools.partial(<function read_excel>, index_col=0), buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'orc': functools.partial(<function read_from_bytes>, <function read_orc>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'sav': functools.partial(<function read_from_bytes>, <function read_spss>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'mat': functools.partial(<function read_from_bytes>, <function mat_bytes_to_dataframe>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), 'arrow': functools.partial(<function read_from_bytes>, <function arrow_bytes_to_dataframe>, buffer_arg_position=0, buffer_arg_name=None, io_buffer_cls=<class '_io.BytesIO'>), '': <function loads>, 'dill': <function loads>}, extension_to_encoder={'csv': functools.partial(<function written_bytes>, functools.partial(<function NDFrame.to_csv>, index=False), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'txt': <method 'encode' of 'str' objects>, 'tsv': functools.partial(<function written_bytes>, functools.partial(<function NDFrame.to_csv>, index=False, sep='\t', escapechar='\\', quotechar='"'), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'json': <dol.util.Pipe object>, 'html': functools.partial(<function written_bytes>, functools.partial(<function DataFrame.to_html>, index=True), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'p': functools.partial(<function written_bytes>, <function NDFrame.to_pickle>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'pickle': functools.partial(<function written_bytes>, <function NDFrame.to_pickle>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'pkl': <built-in function dumps>, 'npy': functools.partial(<function written_bytes>, <function save>, obj_arg_position_in_writer=1, io_buffer_cls=<class '_io.BytesIO'>), 'zip': <function save_df_to_zipped_tsv>, 'h5': functools.partial(<function written_bytes>, <function NDFrame.to_hdf>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'hdf5': functools.partial(<function written_bytes>, <function NDFrame.to_hdf>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'stata': functools.partial(<function written_bytes>, functools.partial(<function DataFrame.to_stata>, write_index=True), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'dta': functools.partial(<function written_bytes>, functools.partial(<function DataFrame.to_stata>, write_index=True), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'sql': functools.partial(<function written_bytes>, <function NDFrame.to_sql>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'sqlite': functools.partial(<function written_bytes>, <function NDFrame.to_sql>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'gbq': functools.partial(<function written_bytes>, <function _to_gbq_unavailable>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'xls': functools.partial(<function written_bytes>, functools.partial(<function NDFrame.to_excel>, index=True), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'xlsx': functools.partial(<function written_bytes>, functools.partial(<function NDFrame.to_excel>, index=True), obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'xml': functools.partial(<function written_bytes>, <function DataFrame.to_xml>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'parquet': functools.partial(<function written_bytes>, <function cast_to_parquet>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'feather': functools.partial(<function written_bytes>, <function DataFrame.to_feather>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'orc': functools.partial(<function written_bytes>, <function DataFrame.to_orc>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'mat': functools.partial(<function written_bytes>, <function dataframe_to_mat_bytes>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), 'arrow': functools.partial(<function written_bytes>, <function dataframe_to_arrow_bytes>, obj_arg_position_in_writer=0, io_buffer_cls=<class '_io.BytesIO'>), '': <function dumps>, 'dill': <function dumps>}), filename_suffix='.dill'))[source]#
Get the user stores for the package.
- Returns:
A dictionary containing paths to various user stores.
- Return type:
- imbed.imbed_project.get_mall(project_id='default_project', *, get_project_mall=<function get_ram_project_mall>, include_signature_stores=True)[source]#
Get the registry mall containing all function stores
- Return type:
- Returns:
A dictionary of stores, each containing registered processing functions
- imbed.imbed_project.validate_component_kind_tables()[source]#
Assert the component-kind tables agree with each other.
They are read in different places — registry lookup, async gating, result storage — and a kind present in one but absent from another is precisely the failure mode this module keeps hitting: a request that resolves fine and is then dropped.