Editor’s introduction
The evaluation focused on the accuracy and contextual appropriateness of generated answers, demonstrating that the architecture supports effective integration of real-world urban data. Findings indicate that the proposed RAG framework, implemented via FIWARE, enables more responsive and contextually grounded AI interactions in urban applications, particularly in a tourism assistant scenario in Madrid.
Introduction
The rise of Generative Artificial Intelligence (AI) in general, and foundation models specifically, has enabled the proliferation of new tools in which Large Language Models (LLMs) become just one component within the software architecture. LLMs are neural networks composed of billions of parameters that have been trained on massive datasets with the task of predicting the next token. The transformer-based architecture, along with Big Data capabilities, has significantly increased LLM performance in recent years.
A limitation of foundation models is that their knowledge is restricted to the dataset on which they were trained and the specific task for which they were designed. Additionally, training a model is extremely costly, both computationally and economically, making it unfeasible to train a new model from scratch just to expand its knowledge base. Alternatives like fine-tuning allow us to modify the behavior of the LLMs. Fine-tuning is less expensive than training a model from scratch, and it works well to adapt the behavior of the model by providing a lot of examples of the desired task, but it is less effective in injecting new knowledge. In addition, it would be necessary to retrain the LLM every time new information needs to be added, making it incompatible with dynamic systems such as cities. Another alternative is Retrieval Augmented Generation (RAG). RAG is a technique applied to LLMs to provide and restrict the LLM to new information not contained in the training dataset. RAG is one of the most widely used techniques for integrating LLMs in specific use cases where contextual information, unknown to the base model, is required. Unlike fine-tuning, which modifies the model’s parameters through a light retraining, RAG allows external information to be injected without altering the base model. This makes RAG more suitable for dynamic systems with frequent information updates.
One of the environments where base foundation models are not sufficient is cities. Urban environments are characterized by being complex ecosystems with multiple data sources that are updated in real time, which were not in the training dataset of the model and with many interconnected systems. The digitalization of cities through the development of smart cities has been one of the main goals of governments worldwide in recent years, with efforts focused on the creation of urban digital twins (DTs). These urban DTs collect real-time data from the physical city through Internet of Things (IoT) sensors, process them within the virtual entity, and, based on the results, modify the state of the city through IoT actuators. Traditionally, DTs have processed information mainly through physical models or machine learning models aimed at predicting the future state of city elements such as traffic congestion. However, these systems have been limited to handling structured data, excluding natural language. The proliferation of Generative AI paves the way for the integration of components into urban environments that are capable of processing natural language. This enables the implementation of more advanced and complex actions designed to improve the lives of citizens, moving toward what is known as Urban General Intelligence.
Retrieval Augmented Generation
RAGs are one of the best options for injecting new knowledge into foundation models without the need to retrain it. The drawback of RAGs is that the new information is not persistent in the model, since it does not modify any of its parameters. Therefore, the maximum amount of information that can be injected is limited by the context window of the model. Additionally, it is necessary to provide the information in each iteration with the model since each prediction starts from the base model. This apparent disadvantage can actually be an advantage for real-time systems, where the value of properties changes over time. If the information was persistent in the LLM, it would need to be able to discern which version of the data is the most recent.
RAGs are used for different purposes, such as answering questions, summarizing texts, text analysis or decision making. If an LLM has been trained up to a certain date, it does not know anything that has happened after that date. For example, LLMs cannot correctly respond to what the weather is like in Paris right now. Another use case of RAGs is to narrow down the context information to the UFM and limit the model’s responses to the desired data. For example, with RAG techniques, you can instruct the model on the specifications of a standard or even tell it to respond that the capital of Italy is Naples. Research has shown how RAG helps reduce possible hallucinations by grounding the model response in retrieved facts, as long as the provided information is accurate.
The processing of a naive RAG is divided into different phases. First, there is the indexing phase, where the data are organized into chunks and indexed in an external data source, typically a vector database. This phase ensures that data are stored in small pieces of data, which allows fast search and retrieval based on the user’s query. It is important to design the chunking strategy controlling the way fragments are divided and the size of each chunk. Once the chunks are generated, an embedding is created for each one. At this stage, it is important to choose an embedding model that fits the RAG, observing that higher-dimensional embeddings provide greater search granularity but also slow down retrieval. When a user submits a prompt, it is compared with the stored embeddings. As a first step, the user’s prompt can be preprocessed and transformed to improve the search. Next, in the retrieval phase, relevant data is obtained from the indexed source based on semantic similarity metrics. The system performs a search query against the indexed database to retrieve content that matches the user’s prompt or context. This phase is crucial to narrow down the most relevant information. There are different retrieval techniques divided into two types of search. In flat searches, all system embeddings are compared. Flat methods offer higher accuracy by exploring all vectors, but are not scalable solutions. On the other hand, Approximate Nearest Neighbors (ANN) methods, such as Locality Sensitive Hashing (LSH), Hierarchical Navigable Small World (HNSW), and Inverted File Index (IVF), speed up retrieval by avoiding the need to compare all possible embeddings. Once the data has been received, a reordering of the top-k most relevant documents can be carried out using reranking techniques. Different data sources can also be merged and the retrieval information can be improved by including neighboring chunks or summaries.
Real-time Spatial RAG for urban environments
The application of generative AI in urban environments is an idea already explored in the literature, which allows adding new functionalities to the city management through queries using natural language, information processing, etc. However, one of the requirements of urban environments is the ability to process data in real-time (or with soft real-time requirements). The concept of real-time in smart cities is broad and encompasses a wide range of scenarios. In systems such as autonomous driving, we deal with hard real-time requirements, where data updates and processing must occur within milliseconds and any delay may cause irreparable damage. In contrast, other systems are less demanding, allowing soft real-time scenarios where information updates can occur in a few seconds. Current architectures based on transformers, which generate information token by token, are not capable of meeting hard real-time requirements so the use of LLMs in urban environments is limited to soft real-time applications. Additionally, in urban environments, there are a large number of elements, so it is important to have the ability to perform preliminary filtering both in time and space to avoid introducing excessive latency in the retrieval and generation phases. Urban environments are characterized by the existence of multiple relationships between their elements. For example, a malfunction of a traffic light can affect the operation of other nearby traffic lights. Therefore, the RAG system must have navigation and self-discovery capabilities among urban entities. One way to achieve this is by representing information as a knowledge graph, which allows augmenting the LLM context by including new entities.
In parallel, the RAG system will connect to the data source, and it will be able to process and respond to external prompts with updated information. In this case, the flow begins at (a) when a user makes a request (req) about a region (R). Next, the request is made to the spatial database for the region (R) and any other additional filters specified by the user (b). This interaction with the spatial database can be defined in multiple ways. The number of entities retrieved can be limited and ordered according to defined criteria, linked elements can also be recovered, and clustering techniques can be applied to enhance the scalability of the system. The response from the spatial database (c, resp-spatial) is combined with the initial user prompt (req + resp-spatial) and sent to an UFM (d). The LLM will be configured with a prompt like “answer the following question: (req) limited to the data (resp-spatial)” resulting in the UFM response (resp-llm) adjusted to the data extracted from the spatial database (e). Finally, the final response (resp) is composed and sent to the user (f). When a user makes a query again, a new interaction with the RAG will begin (a-f). Since flows (1-3) and (a-f) run in parallel, the system is able to react to changes in real-time. The capabilities of spatial databases allow the response size to be limited to the established region, the temporal filtering allows filtering data by date, and the linked data helps to improve the retrieval by including related entities.
This work presents the implementation of a reference architecture capable of operating under the real-time and physical-world interaction requirements typical of smart cities, aligned with the definition of Urban Foundation Models proposed by Zhang et al.. In contrast to the work of Ji and Gao, which focuses on evaluating the intrinsic ability of LLMs to encode geometric text (WKT) and spatial relationships in isolation, the FIWARE-based approach shifts the complexity of spatio-temporal filtering to a standardized Context Broker (NGSI-LD) prior to the generation phase. This approach introduces a key difference with respect to traditional RAG architectures, such as Naive RAG or Graph RAG: the incorporation of a spatial RAG mechanism that filters entities based on their geographic location. By doing so, it reduces the amount of context provided to the model and addresses common issues related to scalability, latency, and hallucinations when LLMs process large volumes of dynamic urban data. Other studies, such as those proposed by Conde et al. or Araujo et al., already suggest the use of FIWARE for smart cities, but they have not explored the integration of LLMs or RAGs.
Results and discussion
We devised a three-stage experimental setup in order to evaluate the efficiency and the quality of the responses generated by our LLM-driven RAG architecture. In the first stage, we conducted a series of tests to assess the ability of the model to provide correct and contextually relevant answers. For this purpose, we tested three regions of increasing size: Small (10 - 20 entities), Medium (100 - 200) and Large (650 - 1300). While these quantities may fit within their context windows, they can still limit the models’ ability to process the information effectively. We selected a representative set of LLMs, including both commercial and open-weight models of different sizes: GPT-5.2, GPT-4.1, GPT-4.1-mini, LLama 3.1 70 B, LLama 3.1 8B, Deepseek V3 685B and Qwen 2.5 7B. The use of commercial models versus open-weight models that can be run locally responds to different operational and contextual needs. Commercial models are generally preferable when maximum performance is required in terms of quality, complex reasoning, and robustness, as well as rapid access to state-of-the-art models. This makes them especially suitable for environments with stable connectivity and where network latency is not critical. In contrast, local models offer clear advantages in scenarios with no connectivity, strict privacy or data sovereignty requirements. They also enable offline operation and predictable latency. In the second stage, we validated our proposal across different architectures by conducting an evaluation that compares with other common RAG solutions: (1) Semantic RAG; (2) Semantic RAG with reranking; (3) Spatial RAG; (4) Spatial RAG combined with Semantic RAG; and (5) Spatial RAG combined with Semantic RAG and reranking. Finally, in the third stage we measured the response times associated with the retrieval and subsequent LLM processing, examining how variations in query parameters, configurations, and data volume influence latency.
To this end, we crafted a set of 24 distinct questions, each representing a different query type derived from the two datasets presented previously (tourism and traffic lights and luminaires). To ensure consistency in the results, no modifications were introduced to the bounding box defining the search area, so all queries targeted the same fixed geographical region. Due to the deterministic nature of the context broker, repeated queries with the same parameters yielded an identical set of entities, thus minimizing variability arising from data retrieval.
Tables 3 and 4 collect all the questions about tourism (QT) and traffic lights and luminaires (QL) and for each of them the number of entities that address under the three different regions: Small, Medium and Large. Each row corresponds to one question, and the entries in each column indicate the number of entities retrieved by the context broker that met the query’s criteria. For instance, when the retrieval limit is set to 10, certain queries (e.g., QT1) match all the available entities. Conversely, other queries (e.g., QT5 under limit 10) yield no matching PoIs in that limited subset, making the only meaningful response that it does not know the answer.
Conclusions and future work
The growing success of Foundation Models in industry, along with their potential for application across an increasing number of domains, highlights the need to standardize their integration into urban environments, taking into account both the components involved and the data flow. In this article, we propose a reference architecture for implementing RAGs in urban environments, as well as an implementation based on FIWARE technology as a comprehensive solution for deploying Foundation Model-based systems in smart cities. This architecture meets all the fundamental requirements of urban environments, including connectivity with IoT devices and third-party systems, scalability, security, and real-time updates, all enabled through geospatial and real-time searches with relationships between entities.
FIWARE, already widely validated in the literature as a robust platform for developing smart city solutions, is presented here as a technology enabler for the inclusion of RAG-based systems in urban contexts. However, although Foundation Models are rapidly evolving, with improvements in speed and larger context windows, significant limitations still remain.
Experiments conducted in three scenarios (with 10–20, 100–200, and 600–1300 entities loaded into the model) show that the main bottleneck lies in the LLM itself, which experiences increased generation times when processing large volumes of information. In addition, a higher tendency to error has been observed as the amount of processed city data increases, even when these data fit within the model context window. However, the results obtained with a moderate number of entities are promising, demonstrating that it is currently feasible to implement RAG systems in urban environments, provided that a careful and efficient selection of relevant information is carried out. Future work should address the scalability limitations of the current evaluation, which does not yet reach volumes of millions of entities, although our proposal is designed to mitigate this issue through horizontal scalability of the components used, the spatial decoupling and the filtering mechanisms that operate at the context broker level, ensuring that only geographically and semantically relevant entities are forwarded to the RAG pipeline.


