Adapting Large Language Models to Emerging Cybersecurity using Retrieval Augmented Generation

Arnabh Borah, Md Tanvirul Alam, Nidhi RastogiarXiv 2025 · DOI

Introduction

The rapid evolution of cybersecurity threats presents a significant challenge for Large Language Models (LLMs). Because these models are static after training, they suffer from "knowledge cutoffs"—an inability to reason about vulnerabilities discovered after their last training date. Furthermore, the high stakes of cybersecurity require transparency and factual precision, areas where standard LLMs often struggle due to hallucinations and a lack of domain-specific grounding.

This paper addresses these hurdles by proposing a specialized Retrieval-Augmented Generation (RAG) framework. Unlike "naive" RAG systems that rely solely on semantic similarity, the proposed approach integrates keyword matching and regular expression (regex) filtering to handle the precise technical identifiers common in Cyber Threat Intelligence (CTI).

Methodology: The Hybrid Sparse-Dense Retriever

The core contribution is a multi-layered retrieval architecture designed to bridge the gap between general linguistic understanding and technical specificity.

Overview of the proposed RAG framework for cybersecurity.

The framework employs a three-tiered strategy:

  1. Dense Retrieval (Semantic): Utilizes the mxbai-embed-large-v1 model and FAISS to identify conceptually relevant documents.
  2. Sparse Retrieval (Keyword): Uses the BM25 algorithm to ensure exact lexical matches for technical terminology.
  3. Regex Matching: Specifically targets CVE identifiers (e.g., CVE-2024-XXXX). When a query contains a known identifier, documents containing that ID receive a significant score boost.

The retrieved context is then passed to a Llama-3-8B-Instruct model, which generates the final response based on the grounded data.

Experimental Setup and Results

The framework was evaluated using the SECURE benchmark, specifically the Knowledge of Common Vulnerabilities (KCV) and Common Weakness Enumeration Test (CWET) subsets. The RAG system was provided with up-to-date 2024 CVE descriptors and the MITRE CWE database.

Performance comparison across different RAG configurations.

The results highlight several critical insights:

  • The Risk of Naive RAG: On the KCV dataset, baseline RAG actually decreased performance (57.6%) compared to the model without RAG (59.2%). This indicates that irrelevant or noisy context can actively mislead the model.
  • The Power of Identifiers: The addition of regex matching for CVE IDs provided the single largest performance jump, raising KCV accuracy from 62.5% to 72.7%.
  • Robustness in Weakness Identification: The "Full Hybrid" approach achieved its highest performance on the CWET dataset with 92.2% accuracy, demonstrating strong capabilities in identifying software weaknesses.

Discussion

Beyond the primary retrieval strategy, the researchers investigated secondary factors affecting performance. They found that model determinism is vital; lower temperatures (0.01) consistently yielded higher accuracy than higher temperatures (0.7 or 1.0), as "creativity" often leads to factual errors in technical contexts.

Additionally, the study compared various embedding models. While larger models generally performed better, the performance gap between a 335M parameter model and a 22.7M parameter model was less than 2%, suggesting that the retrieval architecture (hybrid vs. dense-only) is a more significant factor than the raw size of the embedding model.

Conclusion

This research demonstrates that adapting LLMs for cybersecurity requires moving beyond general-purpose RAG. By incorporating sparse retrieval and regex-based identifier matching, the proposed hybrid framework significantly improves the model's ability to process and reason about emerging threats. Future work will focus on expanding the regex patterns to include other taxonomies like MITRE ATT&CK and exploring multimodal RAG to incorporate visual threat data.

Summary updated

BibTeX
@misc{borah2025adapting,
  author = {Arnabh Borah and Md Tanvirul Alam and Nidhi Rastogi},
  title = {{Adapting Large Language Models to Emerging Cybersecurity using Retrieval Augmented Generation}},
  year = {2025},
  eprint = {2510.27080},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.27080},
}
Figure