Skip to content

server/backend: replace local scoring module with cq.scoring from SDK#367

Merged
peteski22 merged 1 commit into
mainfrom
fix/issue-332-sdk-scoring-import
May 12, 2026
Merged

server/backend: replace local scoring module with cq.scoring from SDK#367
peteski22 merged 1 commit into
mainfrom
fix/issue-332-sdk-scoring-import

Conversation

@peteski22
Copy link
Copy Markdown
Collaborator

Summary

  • Replace server-local scoring usage with cq.scoring imports in backend service/repository paths.
  • Remove duplicated server scoring module and its module-specific backend test.
  • Add backend schema-oracle tests validating serialized KnowledgeUnit payloads against cq_schema.load_schema(\"knowledge_unit\").

Validation

  • make test-server-backend (275 passed)
  • make lint-server-backend (passed)

Notes

  • cq.scoring.calculate_relevance clamps to [0, 1] while the removed server-local copy did not.
  • This is behavior-neutral in practice because signal components are bounded and weights sum to 1.0.

Closes #332

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the backend’s duplicated scoring implementation and switches the server to use the canonical Python implementation from the cq-sdk (cq.scoring). It also adds “schema-as-oracle” tests to validate KnowledgeUnit JSON payloads against the canonical cq-schema definition.

Changes:

  • Swap backend scoring imports to cq.scoring and delete the server-local scoring module and its dedicated test.
  • Add backend schema-oracle tests for KnowledgeUnit JSON validation and include jsonschema as a test dependency.
  • Update lockfile to reflect dependency graph changes.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/backend/src/cq_server/services/knowledge.py Imports scoring helpers from cq.scoring instead of server-local module.
server/backend/src/cq_server/repositories/knowledge.py Imports calculate_relevance from cq.scoring.
server/backend/src/cq_server/scoring.py Removes duplicated scoring implementation.
server/backend/tests/test_store.py Updates tests to import scoring helpers from cq.scoring.
server/backend/tests/test_scoring.py Removes server-local scoring tests.
server/backend/tests/test_schema_oracle.py Adds schema-oracle validation tests for serialized KnowledgeUnit.
server/backend/pyproject.toml Adds jsonschema to the backend test dependency group.
server/backend/uv.lock Updates lockfile for added test dependencies (jsonschema and transitive deps).
Comments suppressed due to low confidence (1)

server/backend/tests/test_schema_oracle.py:49

  • Same issue as the full-unit test: this uses model_dump_json(exclude_none=True) rather than the backend's current serialization behavior. If backend output includes null for optional fields (e.g., superseded_by, flag optional fields), schema validation here won’t catch the mismatch. Align the test and the backend serialization strategy so the oracle reflects what clients/persistence actually see.
def test_minimal_knowledge_unit_validates_against_canonical_schema() -> None:
    unit = create_knowledge_unit(
        domains=["databases"],
        insight=Insight(summary="s", detail="d", action="a"),
    )
    schema = cq_schema.load_schema("knowledge_unit")
    payload = json.loads(unit.model_dump_json(exclude_none=True))
    jsonschema.validate(instance=payload, schema=schema)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/backend/tests/test_schema_oracle.py
@peteski22 peteski22 force-pushed the fix/issue-332-sdk-scoring-import branch from 92fa661 to 5dc3e1c Compare May 12, 2026 20:48
@peteski22 peteski22 merged commit eb8918e into main May 12, 2026
5 checks passed
@peteski22 peteski22 deleted the fix/issue-332-sdk-scoring-import branch May 12, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server/backend: replace local scoring module with cq.scoring from the SDK

2 participants