Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions scripts/ci_role_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ def main() -> None:
raise RuntimeError("Core public exports are unavailable") # noqa: TRY003
if not extras and importlib.util.find_spec("httpx") is not None:
raise RuntimeError("Core installation unexpectedly includes httpx") # noqa: TRY003
if extras:
from powercontext import artifact_plugins
from powercontext import artifact_plugins

if powercontext.artifact_plugins is not artifact_plugins or artifact_plugins.ArtifactFamily is None:
raise RuntimeError("Plugin public export is unavailable") # noqa: TRY003
if powercontext.artifact_plugins is not artifact_plugins or artifact_plugins.ArtifactFamily is None:
raise RuntimeError("Plugin public export is unavailable") # noqa: TRY003
if "cli" in extras:
extras.add("builtin")
with tempfile.TemporaryDirectory(prefix="powercontext-role-") as temporary:
Expand Down
12 changes: 10 additions & 2 deletions src/powercontext/artifacts/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@

from pydantic import BaseModel, ConfigDict, Field, model_validator

from powercontext.builtin.artifacts.memory.models import EmbeddingProfile

Name = Annotated[str, Field(min_length=1, max_length=128, pattern=r"^[a-z][a-z0-9-]*$")]
FieldName = Annotated[str, Field(min_length=1, max_length=128)]
Version = Annotated[str, Field(min_length=1, max_length=128, pattern=r".*\S.*")]
SearchMode = Literal["text", "vector", "hybrid"]


class EmbeddingProfile(BaseModel):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve the profile's historical schema identity

For plugin content containing both the builtin profile and a distinct model named EmbeddingProfile, this move changes Pydantic's module-qualified $defs keys and $ref values, as reproduced against the base definition. Consequently, ArtifactPluginManager._validate_identity rejects the unchanged plugin on reload with an artifact_schema conflict; preserve the historical schema identity and add regression coverage for colliding model names.

"""The Memory embedding index contract for one deployment."""

profile_id: str
model: str
dimension: int
distance: Literal["l2"] = "l2"
normalization: Literal["none", "unit"] = "unit"


class _Declaration(BaseModel):
model_config = ConfigDict(extra="forbid", frozen=True, allow_inf_nan=False)

Expand Down
11 changes: 1 addition & 10 deletions src/powercontext/builtin/artifacts/memory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pydantic import BaseModel, Field, model_validator

from powercontext.artifacts import Artifact, ArtifactRef
from powercontext.artifacts.indexes import EmbeddingProfile
from powercontext.builtin.artifacts.search import AdmissionCounts
from powercontext.builtin.inference.models import InferenceUsage
from powercontext.sources import Source, SourceRef
Expand All @@ -34,16 +35,6 @@
MemoryMatchedBy: TypeAlias = Literal["fts", "vector"]


class EmbeddingProfile(BaseModel):
"""The Memory embedding index contract for one deployment."""

profile_id: str
model: str
dimension: int
distance: Literal["l2"] = "l2"
normalization: Literal["none", "unit"] = "unit"


@dataclass(frozen=True)
class MemoryQueryEmbedding:
"""One already-computed query vector together with the profile it was computed under.
Expand Down
50 changes: 50 additions & 0 deletions tests/e2e/test_artifact_vector_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
"""Installed Server and spawned generation Worker share text/vector/hybrid search."""

import asyncio
from pathlib import Path

from sqlalchemy import create_engine, select, update

from powercontext.builtin.persistence.oceanbase import OceanBaseConfig
from powercontext.builtin.persistence.tables import (
ARTIFACT_FAMILY_SCHEMAS_TABLE,
ARTIFACT_PROCESSING_BINDING_STATES_TABLE,
)
from tests.builtin.persistence.test_artifact_indexes import PROFILE, body
from tests.e2e.test_artifact_plugin_search import _PIPELINE, _write_report
from tests.e2e.test_artifact_plugins import (
Expand Down Expand Up @@ -57,6 +64,21 @@ class SearchReport(IncidentReport):
inputs = InputContract(projections=inputs.projections, artifact_families=("experience", "skill", "profile"))
"""

# Existing registrations persisted this definition inside their content schema.
_PERSISTED_EMBEDDING_PROFILE = {
"description": "The Memory embedding index contract for one deployment.",
"properties": {
"dimension": {"title": "Dimension", "type": "integer"},
"distance": {"const": "l2", "default": "l2", "title": "Distance", "type": "string"},
"model": {"title": "Model", "type": "string"},
"normalization": {"default": "unit", "enum": ["none", "unit"], "title": "Normalization", "type": "string"},
"profile_id": {"title": "Profile Id", "type": "string"},
},
"required": ["profile_id", "model", "dimension"],
"title": "EmbeddingProfile",
"type": "object",
}


def test_vector_search_through_http_and_spawned_worker(migration_backend):
config, directory = migration_backend.config, migration_backend.directory
Expand Down Expand Up @@ -129,3 +151,31 @@ async def exercise():
assert historical.json()["content"] == first["content"]

asyncio.run(exercise())


def test_reload_accepts_embedding_profile_schema_persisted_by_existing_registration(tmp_path: Path) -> None:
async def exercise():
async with running_server(tmp_path) as client:
scope = await create_scope(client, "vector-upgrade")
plugin = deploy_plugin(EXAMPLE, tmp_path / "vector-plugin", [scope])
entry = plugin / "plugin.py"
entry.write_text(entry.read_text() + _DECLARATION + _PIPELINE, encoding="utf-8")
await reload_plugin(client, tmp_path, plugin, 0)
# Rewrite the saved registration and family schema as the existing release persisted them.
schemas, states = ARTIFACT_FAMILY_SCHEMAS_TABLE, ARTIFACT_PROCESSING_BINDING_STATES_TABLE
family = schemas.c.family == "incident-report"
binding = states.c.binding_name == "incident-reports"
engine = create_engine(f"sqlite:///{tmp_path / 'server.db'}")
try:
with engine.begin() as connection:
declaration = connection.scalar(select(schemas.c.declaration).where(family))
declaration["content_schema"]["$defs"]["EmbeddingProfile"] = _PERSISTED_EMBEDDING_PROFILE
Comment thread
hidb4ai marked this conversation as resolved.
Resolved
connection.execute(update(schemas).where(family).values(declaration=declaration))
spec = connection.scalar(select(states.c.plugin_spec).where(binding))
spec["declaration"]["content_schema"]["$defs"]["EmbeddingProfile"] = _PERSISTED_EMBEDDING_PROFILE
connection.execute(update(states).where(binding).values(plugin_spec=spec))
finally:
engine.dispose()
await reload_plugin(client, tmp_path, plugin, 1)

asyncio.run(exercise())
Loading