Terminology Enhanced Retrieval Augmented Generation for S panish Legal Corpora (2025)

Abstract: This paper intends to highlight the importance of reusing terminologies in the context of Large Language Models (LLMs), particularly within a Retrieval-Augmented Generation (RAG) scenario. We explore the application of query expansion techniques using a controlled terminology enriched with synonyms. Our case study focuses on the Spanish legal domain, investigating both query expansion and improvements in retrieval effectiveness within the RAG model. The experimental setup includes various LLMs, such as Mistral, LLaMA3.2, and Granite 3, along with multiple Spanish-language embedding models. The results demonstrate that integrating current neural approaches with linguistic resources enhances RAG performance, reinforcing the role of structured lexical and terminological knowledge in modern NLP pipelines.

## introduction the increasing complexity of legal texts and the demand for efficient legal information retrieval have led to the exploration of different types of advanced natural language processing (nlp) techniques. at the european level, several initiatives can be found, such as the eur-lex platform foot_0 , that provides access to european union law, including treaties, legislation, case law, and legislative proposals, being a crucial resource for legal professionals seeking comprehensive legal information within the eu framework. in terms of data standardisation, the european case law identifier (ecli) was created to standardize the citation of case law across europe. by introducing a uniform identifier and a set of metadata, ecli facilitates easier access and citation of european case law, enhancing the efficiency of legal information retrieval systems. the eu-supported h2020 lynx project incorporated both initiatives to create a knowledge-driven ai service platform. this platform was designed for content processing, enhancement, and analysis within the legal sector, with the main aim of aiding companies in efficiently tackling compliance challenges across different languages and legal systems @xcite . however, one of the key limitations of projects of that kind is the challenge of processing legal texts in low-resource languages, such as spanish. traditional nlp techniques, such as rule-based approaches and classical machine learning models, struggle with the complexity of legal language, which often includes long sentences, archaic terms, and jurisdiction-specific terminology. in this project, different language resources were generated but, still, the data scarcity limited the effectiveness of semantic search and entity recognition, making legal information retrieval in spanish less accurate and comprehensive compared to other european languages. currently, large language models (llms) have become an unprecedented artificial intelligence resource for processing and querying information. however, in critical domains such as the legal sector, these models cannot rely only on outdated training data or generate hallucinations @xcite . moreover, legal domain vocabulary and terminology evolve over time, requiring continuous adaptation. in this context, retrieval-augmented generation (rag) @xcite has emerged as a promising solution to these issues, combining the strengths of retrieval-based and generative models to improve the accuracy and relevance of automated legal text processing. this paper investigates the effectiveness of the combination of terminologies in the context of rag scenarios. in particular, through a query expansion technique and a reranking process. this study has been performed over the spanish legal domain, relying on spanish language models for the embedding process and llms such as llama, mistral and granite. the experiments are available in an open repository foot_1 . ## related work the rapid advancement of llms has boosted nlp applications across different domains. llm-driven pipelines have demonstrated significant capabilities in text comprehension @xcite , generation @xcite , and data retrieval @xcite . yet, llms present some limitations, the most notable being the lack of specific knowledge in specialised domains, hallucinations, and the high computational resources required for model updates @xcite . to address these challenges, significant efforts have been made in the implementation of rag, leveraging its advantages to enhance the capabilities of llms in tasks that require a high level of recent and accurate knowledge, including question answering, ai4science foot_2 and software engineering @xcite . rag systems help such tasks by providing the llm with objective data from external resources to generate accurate responses @xcite , using various fact-identification mechanisms @xcite . additionally, other studies have demonstrated that rag can effectively reduce hallucinations in conversational tasks by providing the model with verified and contextualized information @xcite . still, these limitations are specially relevant in fields such as medicine and law, where the reliability of information is essential. for instance, recent studies have shown that hallucinations in the legal domain are particularly frequent and concerning, with rates ranging between 69% and 88% in responses to legal queries made to some of the most advanced llms @xcite . previous research has shown that domain-specific pretraining significantly improves llm performance in technical fields, such as law @xcite . additionally, recent advancements in model fine-tuning, such as reinforcement learning from human feedback (rlhf), have enhanced llm adaptability to domain-specific language @xcite . other approaches have started to apply this technique for the generation of documen-tation in spanish public entities @xcite . despite the efforts mentioned above, there is room for research on the application of rag models in the legal domain, particularly for languages with limited nlp resources such as spanish. while advancements have been made in adapting llms to legal contexts, to the best of our knowledge, there are still few studies specifically focused on ragbased experiments that leverage language resources for spanish legal texts, which highlights the need for further exploration of such techniques to tackle the complexities of spanish legal language. ## evaluation to assess the proposal of this work, we employed several standard nlp evaluation metrics that measure the quality of the generated responses from different perspectives: ## conclusions and future work this paper proposes the implementation of a rag system to enhance the use of terminologies along llms in the context of spanish legal texts, particularly the spanish workers' statute. specifically, this work intends to research the impact in the information retrieval step of incorporating query expansion techniques enriched with synonyms and related terms from legal terminologies. we evaluate three llms, including mistral, llama3.2, and granite3-dense and two spanish embedding models. the results confirm that integrating neural language models with curated linguistic resources enhances rag performance, highlighting the value of structured language data in modern nlp applications. however, we have observed a low recall of the synonyms from the terminology, which translates in a low number of questions expanded. this limitation highlights the need for generating more complex and specific terminological resources, includ-ing a deeper research on automatic terminology extraction algorithms that are able to identify specific terms in the domain. on the other hand, the results emphasize the need for expanding spanish legal corpora with larger annotated datasets (for question answering, in this case) to improve model evaluation. additionally, integrating structured legal data, such as court rulings, with unstructured text can enhance retrieval capabilities. future research envisions the development of adaptive rag models that dynamically adjust to legal question complexity using techniques such as reinforcement learning.