Modern trajectory predictors increasingly condition on external spatial context, such as map geometry, signed distance fields (SDFs), and nearby moving agents. While this context improves prediction quality, constructing it for every training anchor has become a hidden systems bottleneck. In a representative maritime AIS pipeline, spatial context construction requires roughly 17 CPU-days for a 5.48M-anchor corpus, dominating the cost of the downstream predictor. We present M-CTX, an exact and scalable spatial context-retrieval framework for trajectory analytics. M-CTX recasts context construction as an ingest-once, query-many spatial database workload and replaces three brute-force stages -- OSM range retrieval, SDF computation, and moving-vessel neighbour lookup -- with composable, index-backed operators. Its learned range-index backend, BR-LZ, provides recall-complete MBR-overlap range retrieval and reduces candidate amplification by 1.1x--2.7x relative to global-expansion one-curve baselines. Across four maritime regions, eight baseline systems, synthetic workloads with up to 40M spatial features, and 10^7-record AIS streams, M-CTX reproduces the reference context exactly. On the 5.48M-anchor corpus, it reduces context construction from about 17 CPU-days to 1.8 hours, a measured 226x end-to-end speed-up. An optional storage mode further compresses SDF context by 64x with only a 0.04 m ADE change. These results establish exact spatial context retrieval as a first-class database problem in modern trajectory analytics. Code and datasets are publicly available at https://github.com/mark000071/M-CTX-Traj.
翻译:现代轨迹预测模型日益依赖外部空间上下文,如地图几何、符号距离场(SDF)及邻近移动智能体。尽管此类上下文能提升预测质量,但为每个训练锚点构建上下文已成为隐藏的系统瓶颈。在典型的海事AIS处理流程中,为含548万个锚点的语料库构建空间上下文需耗费约17 CPU天,其成本远超下游预测器。本文提出M-CTX——一个面向轨迹分析的高精度可扩展空间上下文检索框架。M-CTX将上下文构建重新定义为"一次摄入、多次查询"的空间数据库工作负载,并将三个暴力计算阶段(OSM范围检索、SDF计算及移动船舶邻域查找)替换为基于索引的可组合算子。其学习型范围索引后端BR-LZ可实现召回完备的MBR重叠范围检索,相较全局扩展的单曲线基线方法将候选集放大程度降低1.1-2.7倍。在四个海域、八个基线系统、含4000万个空间特征的合成工作负载及千万级记录AIS数据流上的实验表明,M-CTX可精确复现参考上下文。针对548万锚点语料库,M-CTX将上下文构建时间从约17 CPU天缩短至1.8小时,实测端到端加速比达226倍。可选存储模式可额外实现64倍SDF上下文压缩,仅带来0.04米ADE变化。这些成果将精确空间上下文检索确立为现代轨迹分析中的一类基础数据库问题。代码与数据集开源发布在https://github.com/mark000071/M-CTX-Traj。