Enhancing Geospatial Reasoning in Large Language Models: An Optimized Retriever Approach Using R-Tree-Based Point-in-Polygon and Nearest Neighbor Search
摘要
The geographic analytical capabilities of large language models (LLMs) present significant prospects in fields like geographic information systems (GISs), urban planning, and autonomous navigation. However, recent research has exposed biases in LLMs, particularly in spatial reasoning and geographical retrieval tasks, where the inherent biases in the training data can compromise their accuracy. Retrieval-augmented generation (RAG) could limit these biases; however, integrating specific geographical RAG presents computational challenges due to the complexity of spatial data processing and standard tokenization of geo-coordinates. In this paper, we propose a retriever to enable geography-aware RAG for text queries to an LLM that requires a point-in-polygon (PIP) search. We extend the Retriever to perform standard PIP with an R-Tree followed by a standard semantic similarity-based nearest neighbor search. First, we benchmark our approach against two baseline approaches on single-core performance to find significant speedup. Finally, we qualitatively examine the responses across a no RAG, classic semantic similarity RAG, and our proposed Retriever’s RAG as a case study on a specific query. The quality of our responses is better than comparable approaches for the tested query on Llama 3.1-8B and ChatGPT 4o, 4o mini, and o1.