Skip to content

Latest commit

 

History

History
149 lines (117 loc) · 5.53 KB

README.md

File metadata and controls

149 lines (117 loc) · 5.53 KB

rec-proto

rec-proto contains the Java wire contract shared by rec-server, the Java SDK, and example data loaders. It consists of serializable POJOs and enums without Spring or transport dependencies.

<dependency>
    <groupId>com.openrec</groupId>
    <artifactId>rec-proto</artifactId>
    <version>0.2.0</version>
</dependency>

Build and run with JDK 21. Like graph/contrib and the SDK, this module targets --release 21; it no longer provides a Java 8 compatibility artifact. Run mvn install from the rec-server root before building consumers against a local snapshot.

Envelope

Every request and response uses a common envelope:

class JsonReq<T> {
    String requestId;
    T body;
}

class JsonRes<T> {
    int code;
    boolean status;
    String msg;
    T data;
}

The server places requestId in the logging MDC. Clients should set it when they need end-to-end trace correlation; otherwise the request model generates a UUID. ProtoCode defines the standard HTTP-style result codes. JsonResType helps Gson deserialize JsonRes<T> despite type erasure.

Entities

Item, User, and Event represent the records accepted by the push APIs. Time fields are strings containing epoch seconds. extFields preserves application-specific attributes not covered by the core model.

Important compatibility details:

  • Item.tags is a comma-separated string, while User.tags is List<String>.
  • Event type values are free-form, but click, expose, and dislike have built-in serving behavior for triggers and filters.
  • In cluster mode rec-server reserves Event.extFields._openrecItemContext for the category, subcategory, and non-negative price snapshot resolved before the event is published. Producers may supply other extFields; the reserved entry is replaced by OpenRec.
  • Entity field names and serialized forms are shared contracts; update SDK and example consumers when changing them.

Push contract

ItemReq, UserReq, and EventReq extend the same batch request:

class AbstractPushReq<T> {
    PushCmd cmd = PushCmd.INSERT;
    List<T> data;
}

enum PushCmd { INSERT, UPDATE, DELETE }

INSERT and UPDATE are upserts in the current server implementations. User/item DELETE removes entities by ID. Event DELETE is mode-specific: standalone removes the supplied item IDs from the user/scene/type Redis sorted set, rather than deleting historical events by ID; cluster rejects event deletion through the public push API. Downstream event-tombstone support is a separate mutation-consumer contract. The active Spring profile decides whether accepted mutations are written directly to Redis or published as versioned Kafka messages.

Recommendation contract

class RecommendReq {
    String scene;
    int size;
    String userId;
    String deviceId;
    List<String> itemIds;
    String type;
    boolean debug;
    String targetType;
    Map<String, Object> params;
}

class RecommendRes<T> {
    List<ScoreResult> results;
    List<T> detailInfos;
    List<RecallDiagnostic> recallDiagnostics;
}

class RecallDiagnostic {
    String node;
    String channel;
    String status;
    int candidateCount;
}

debug=true attaches item/user entity details and request-scoped recallDiagnostics. Each recall diagnostic reports the node status and its committed candidate count before filtering, merging, ranking and final truncation. An item returned by two recall nodes counts toward both channels, even if it does not reach the final results. Disabled nodes report DISABLED; failed or timed-out nodes report their execution status and zero candidates. Diagnostics are unset for normal requests. This additive field does not change existing result attribution.

Recommendation endpoints return HTTP 503 until the selected target/experiment graph is ready; /health is liveness and /ready is the recommendation admission check. See the readiness setup for warmup samples and authentication.

targetType is assigned by /api/recommend/item or /api/recommend/user; both endpoints execute their respective serving graph.

GraphEngine.prepare() exposes RecommendReq fields to nodes by field name. Renaming one is therefore a serving-graph contract change, not a cosmetic refactor.

The item graph accepts a dense request vector in params.queryEmbedding. The query embedding recall node uses it against the configured query_qwen_emb index. Keeping the vector in params preserves compatibility for SDKs and callers that do not use semantic query recall.

Scores and recall provenance

ScoreResult carries the final ordering score and the contributions used to derive it:

Field Meaning
id Item ID
score Final score used for sorting
recallFrom First recall channel that produced the item
recallScore Score from recallFrom, or null if recall did not run
recallFusionScore Aggregated multi-channel recall score
rankScore Rank-engine contribution, or null on bypass or fallback after failure/timeout
recallScores Insertion-ordered map of every recall channel and its score

An item recalled by several channels is emitted once while retaining all channel contributions. VectorResult is the separate id plus item-sequence-vector carrier used by item_seq_emb.

Compatibility

Changes in this module can affect sdk/java-client, openrec/init, openrec/web, and serialized Kafka or HTTP payloads. Preserve backward parsing where possible and verify those consumers for any field, enum, or envelope change.