server/backend: replace local scoring module with cq.scoring from SDK#367
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.scoringand delete the server-local scoring module and its dedicated test. - Add backend schema-oracle tests for
KnowledgeUnitJSON validation and includejsonschemaas 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 includesnullfor 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.
92fa661 to
5dc3e1c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cq.scoringimports in backend service/repository paths.KnowledgeUnitpayloads againstcq_schema.load_schema(\"knowledge_unit\").Validation
make test-server-backend(275 passed)make lint-server-backend(passed)Notes
cq.scoring.calculate_relevanceclamps to[0, 1]while the removed server-local copy did not.1.0.Closes #332