Table of Contents
Fetching ...

DFA-RAG: Conversational Semantic Router for Large Language Model with Definite Finite Automaton

Yiyou Sun, Junjie Hu, Wei Cheng, Haifeng Chen

TL;DR

DFA-RAG tackles regulated LLM dialogue by embedding a learnable Definite Finite Automaton (DFA) as a semantic router. The DFA is defined as $(Q,\Sigma,\delta,q_0,F)$ and is learned from training dialogues by extracting tag sequences and building a tag-based DFA with state-tracking function $\\mathcal{I}(q)$; similar states are merged using the similarity score $\\phi_{sim}(q,q')$ with threshold $\\lambda$. Retrieval-augmented generation then couples this DFA with context-aware sample retrieval to guide responses, yielding interpretable, domain-specific dialogue with improved win-rates over baselines. Experiments on diverse datasets including MultiWOZ show high Inform and Success scores (e.g., Inform ≈ 93.3, Success ≈ 90.0) and strong generation quality, supporting the practical utility of plug-and-play DFA routing for trustworthy AI assistants.

Abstract

This paper introduces the retrieval-augmented large language model with Definite Finite Automaton (DFA-RAG), a novel framework designed to enhance the capabilities of conversational agents using large language models (LLMs). Traditional LLMs face challenges in generating regulated and compliant responses in special scenarios with predetermined response guidelines, like emotional support and customer service. Our framework addresses these challenges by embedding a Definite Finite Automaton (DFA), learned from training dialogues, within the LLM. This structured approach acts as a semantic router which enables the LLM to adhere to a deterministic response pathway. The routing is achieved by the retrieval-augmentation generation (RAG) strategy, which carefully selects dialogue examples aligned with the current conversational context. The advantages of DFA-RAG include an interpretable structure through human-readable DFA, context-aware retrieval for responses in conversations, and plug-and-play compatibility with existing LLMs. Extensive benchmarks validate DFA-RAG's effectiveness, indicating its potential as a valuable contribution to the conversational agent.

DFA-RAG: Conversational Semantic Router for Large Language Model with Definite Finite Automaton

TL;DR

DFA-RAG tackles regulated LLM dialogue by embedding a learnable Definite Finite Automaton (DFA) as a semantic router. The DFA is defined as and is learned from training dialogues by extracting tag sequences and building a tag-based DFA with state-tracking function ; similar states are merged using the similarity score with threshold . Retrieval-augmented generation then couples this DFA with context-aware sample retrieval to guide responses, yielding interpretable, domain-specific dialogue with improved win-rates over baselines. Experiments on diverse datasets including MultiWOZ show high Inform and Success scores (e.g., Inform ≈ 93.3, Success ≈ 90.0) and strong generation quality, supporting the practical utility of plug-and-play DFA routing for trustworthy AI assistants.

Abstract

This paper introduces the retrieval-augmented large language model with Definite Finite Automaton (DFA-RAG), a novel framework designed to enhance the capabilities of conversational agents using large language models (LLMs). Traditional LLMs face challenges in generating regulated and compliant responses in special scenarios with predetermined response guidelines, like emotional support and customer service. Our framework addresses these challenges by embedding a Definite Finite Automaton (DFA), learned from training dialogues, within the LLM. This structured approach acts as a semantic router which enables the LLM to adhere to a deterministic response pathway. The routing is achieved by the retrieval-augmentation generation (RAG) strategy, which carefully selects dialogue examples aligned with the current conversational context. The advantages of DFA-RAG include an interpretable structure through human-readable DFA, context-aware retrieval for responses in conversations, and plug-and-play compatibility with existing LLMs. Extensive benchmarks validate DFA-RAG's effectiveness, indicating its potential as a valuable contribution to the conversational agent.
Paper Structure (31 sections, 3 equations, 11 figures, 3 tables)

This paper contains 31 sections, 3 equations, 11 figures, 3 tables.

Figures (11)

  • Figure 1: Illustration of the DFA-RAG Framework. (a) shows the training set with dialogues. (b) demonstrates the Definite Finite Automaton (DFA) which represents the workflow learned from the dialogues. Blue and green dots represent the states of the user and system respectively. The states are transited by keywords in conversations. (c) outlines the DFA-based In-Context Learning process, where the LLM is guided by the DFA to provide contextually relevant responses. (d) showcases sample conversations between a user and the LLM.
  • Figure 2: A demo of DFA recognizing string "$(ab)^*$".
  • Figure 3: Illustration of the algorithm for building a tag tree, expressed in Python-style pseudocode. (1) Positioned centrally is the core algorithm, flanked on either side by demonstrative examples that "print out" the algorithm's internal variables at various "breakpoints". (2) On the left, we begin by displaying the input data used in the demonstration. Following this, the first breakpoint, corresponding to Line 1 of the algorithm, showcases the variables storing the ID-ed tag sets across different conversational rounds. (3) Shifting to the right side, we illustrate the evolution of the variables and the tree structures, starting from round 0 with the initial state $q_0$ . The breakpoints at Lines 15 $\&$ 16 forego stepping into the function, instead presenting the completed tree structures directly for clarity. To simplify the illustration, we omit the iterative process for rounds 1 $\&$ 2, jumping straight to the final results.
  • Figure 4: Outline for Section \ref{['sec:learn_dfa']}.
  • Figure 5: DFA Results for MultiWOZ. (a) This segment of the figure illustrates a portion of the constructed DFA. The black circle indicates the starting point of the automaton. Each green circle represents a "user" state, while each blue circle denotes a "system" state. The states are interconnected by arrows, each labeled with a tag. Note that some lines are interconnected (ex. lines correspond to"name" and "area"), it means that the relevant nodes are connected in both ways. (b) A specific path within the DFA is highlighted to demonstrate its correspondence with actual dialogues traversed. In these dialogues, elements associated with the tags are emphasized in bold.
  • ...and 6 more figures