-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.py
More file actions
202 lines (199 loc) · 10.9 KB
/
schema.py
File metadata and controls
202 lines (199 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from __future__ import annotations
from backend.app.core.domain_schema import (
EntitySpec,
FieldSpec,
RelationshipSpec,
)
ENTITY_SPECS: tuple[EntitySpec, ...] = (
EntitySpec(
class_name="Customer",
redis_key_template="electrohub_customer:{customer_id}",
file_name="customers.jsonl",
id_field="customer_id",
fields=(
FieldSpec("customer_id", "str", "Unique customer identifier", is_key_component=True),
FieldSpec("name", "str", "Customer full name", index="text", weight=2.0),
FieldSpec("email", "str", "Customer email", index="text", weight=1.5, no_stem=True),
FieldSpec("city", "str", "Customer city", index="tag"),
FieldSpec("state", "str", "Customer state", index="tag"),
FieldSpec("member_tier", "str", "Loyalty membership tier", index="tag"),
FieldSpec("home_store_id", "str", "Preferred local store", index="tag"),
FieldSpec("home_store_name", "str", "Preferred store name", index="text"),
FieldSpec("account_created_at", "str", "ISO timestamp for account creation"),
),
relationships=(
RelationshipSpec("orders", "Orders placed by this customer", "customer_id"),
RelationshipSpec("support_cases", "Support cases opened by this customer", "customer_id"),
),
),
EntitySpec(
class_name="Store",
redis_key_template="electrohub_store:{store_id}",
file_name="stores.jsonl",
id_field="store_id",
fields=(
FieldSpec("store_id", "str", "Unique store identifier", is_key_component=True),
FieldSpec("name", "str", "Store name", index="text", weight=2.0),
FieldSpec("city", "str", "Store city", index="tag"),
FieldSpec("state", "str", "Store state", index="tag"),
FieldSpec("zip_code", "str", "Store ZIP code", index="tag"),
FieldSpec("address", "str", "Street address"),
FieldSpec("phone", "str", "Store phone number"),
FieldSpec("pickup_supported", "bool", "Whether in-store pickup is supported"),
FieldSpec("curbside_supported", "bool", "Whether curbside pickup is supported"),
FieldSpec("services", "str", "Key services available at the store", index="text"),
FieldSpec("hours_summary", "str", "Store operating hours"),
),
),
EntitySpec(
class_name="Product",
redis_key_template="electrohub_product:{product_id}",
file_name="products.jsonl",
id_field="product_id",
fields=(
FieldSpec("product_id", "str", "Unique product identifier", is_key_component=True),
FieldSpec("sku", "str", "Retail SKU", index="tag", no_stem=True),
FieldSpec("name", "str", "Product name", index="text", weight=2.2),
FieldSpec("brand", "str", "Product brand", index="tag"),
FieldSpec("category", "str", "Top-level category", index="tag"),
FieldSpec("subcategory", "str", "Subcategory", index="tag"),
FieldSpec("form_factor", "str", "Form factor such as laptop or desktop", index="tag"),
FieldSpec("price", "float", "Current selling price", index="numeric", sortable=True),
FieldSpec("sale_price", "float | None", "Current promotional price", index="numeric"),
FieldSpec("rating", "float", "Average customer rating", index="numeric", sortable=True),
FieldSpec("availability_status", "str", "Overall availability status", index="tag"),
FieldSpec("pickup_eligible", "bool", "Whether local pickup is available"),
FieldSpec("shipping_eligible", "bool", "Whether shipping is available"),
FieldSpec("specs_summary", "str", "Readable hardware summary", index="text"),
FieldSpec("use_cases", "str", "Suggested workloads and use cases", index="text"),
FieldSpec("ai_fit_summary", "str", "Short AI-authored fit summary", index="text", weight=1.4),
FieldSpec("search_text", "str", "Combined searchable description for product discovery", index="text", weight=1.8),
),
),
EntitySpec(
class_name="StoreInventory",
redis_key_template="electrohub_store_inventory:{inventory_id}",
file_name="store_inventory.jsonl",
id_field="inventory_id",
fields=(
FieldSpec("inventory_id", "str", "Unique inventory row identifier", is_key_component=True),
FieldSpec("store_id", "str", "Store identifier", index="tag"),
FieldSpec("product_id", "str", "Product identifier", index="tag"),
FieldSpec("store_name", "str", "Store name", index="text"),
FieldSpec("product_name", "str", "Product name", index="text"),
FieldSpec("quantity_available", "int", "Quantity currently available", index="numeric", sortable=True),
FieldSpec("pickup_status", "str", "Pickup readiness status", index="tag"),
FieldSpec("pickup_eta_hours", "int", "Estimated pickup wait time in hours", index="numeric"),
FieldSpec("aisle_location", "str | None", "Approximate floor or aisle location"),
),
relationships=(
RelationshipSpec("store", "Store carrying this item", "store_id"),
RelationshipSpec("product", "Product stocked at the store", "product_id"),
),
),
EntitySpec(
class_name="Order",
redis_key_template="electrohub_order:{order_id}",
file_name="orders.jsonl",
id_field="order_id",
fields=(
FieldSpec("order_id", "str", "Unique order identifier", is_key_component=True),
FieldSpec("customer_id", "str", "Customer identifier", index="tag"),
FieldSpec("status", "str", "Order status", index="tag"),
FieldSpec("fulfillment_type", "str", "shipping or pickup", index="tag"),
FieldSpec("store_id", "str | None", "Pickup store identifier", index="tag"),
FieldSpec("store_name", "str | None", "Pickup store name", index="text"),
FieldSpec("order_total", "float", "Total order amount", index="numeric", sortable=True),
FieldSpec("order_date", "str", "ISO timestamp when the order was placed"),
FieldSpec("promised_date", "str | None", "Promised delivery or pickup timestamp"),
FieldSpec("delivered_at", "str | None", "Actual delivery timestamp"),
FieldSpec("tracking_number", "str | None", "Carrier tracking number", index="tag", no_stem=True),
FieldSpec("shipping_address", "str | None", "Delivery address"),
FieldSpec("summary", "str", "Short order summary", index="text"),
),
),
EntitySpec(
class_name="OrderItem",
redis_key_template="electrohub_order_item:{order_item_id}",
file_name="order_items.jsonl",
id_field="order_item_id",
fields=(
FieldSpec("order_item_id", "str", "Unique order item identifier", is_key_component=True),
FieldSpec("order_id", "str", "Parent order identifier", index="tag"),
FieldSpec("product_id", "str", "Product identifier", index="tag"),
FieldSpec("product_name", "str", "Product name", index="text"),
FieldSpec("quantity", "int", "Quantity ordered", index="numeric"),
FieldSpec("unit_price", "float", "Unit selling price", index="numeric"),
FieldSpec("fulfillment_status", "str", "Line-item fulfillment status", index="tag"),
),
),
EntitySpec(
class_name="Shipment",
redis_key_template="electrohub_shipment:{shipment_id}",
file_name="shipments.jsonl",
id_field="shipment_id",
fields=(
FieldSpec("shipment_id", "str", "Unique shipment identifier", is_key_component=True),
FieldSpec("order_id", "str", "Parent order identifier", index="tag"),
FieldSpec("carrier", "str", "Shipping carrier", index="tag"),
FieldSpec("tracking_number", "str", "Tracking number", index="tag", no_stem=True),
FieldSpec("shipment_status", "str", "Shipment status", index="tag"),
FieldSpec("shipped_at", "str", "Timestamp when the shipment left the warehouse"),
FieldSpec("estimated_delivery", "str | None", "Current estimated delivery timestamp"),
FieldSpec("last_scan_at", "str | None", "Timestamp of the latest scan"),
FieldSpec("current_location", "str | None", "Latest known shipment location", index="text"),
FieldSpec("delay_reason", "str | None", "Reason for any delay", index="text"),
),
),
EntitySpec(
class_name="ShipmentEvent",
redis_key_template="electrohub_shipment_event:{event_id}",
file_name="shipment_events.jsonl",
id_field="event_id",
fields=(
FieldSpec("event_id", "str", "Unique shipment event identifier", is_key_component=True),
FieldSpec("shipment_id", "str", "Shipment identifier", index="tag"),
FieldSpec("order_id", "str", "Order identifier", index="tag"),
FieldSpec("event_type", "str", "Shipment event type", index="tag"),
FieldSpec("timestamp", "str", "Event timestamp"),
FieldSpec("location", "str | None", "Event location", index="text"),
FieldSpec("description", "str", "Human-readable event description", index="text"),
),
),
EntitySpec(
class_name="SupportCase",
redis_key_template="electrohub_support_case:{case_id}",
file_name="support_cases.jsonl",
id_field="case_id",
fields=(
FieldSpec("case_id", "str", "Unique support case identifier", is_key_component=True),
FieldSpec("customer_id", "str", "Customer identifier", index="tag"),
FieldSpec("order_id", "str | None", "Related order identifier", index="tag"),
FieldSpec("category", "str", "Support case category", index="tag"),
FieldSpec("status", "str", "Support case status", index="tag"),
FieldSpec("opened_at", "str", "Case open timestamp"),
FieldSpec("summary", "str", "Short support summary", index="text"),
FieldSpec("resolution", "str | None", "Resolution summary", index="text"),
),
),
EntitySpec(
class_name="Guide",
redis_key_template="electrohub_guide:{guide_id}",
file_name="guides.jsonl",
id_field="guide_id",
fields=(
FieldSpec("guide_id", "str", "Unique guide identifier", is_key_component=True),
FieldSpec("title", "str", "Guide title", index="text", weight=2.0),
FieldSpec("category", "str", "Guide category", index="tag"),
FieldSpec("content", "str", "Guide body", index="text"),
FieldSpec(
"content_embedding",
"list[float]",
"Vector embedding for the guide content",
index="vector",
vector_dim=1536,
distance_metric="COSINE",
),
),
),
)