TL;DR
Semantic XPath is a novel tree-structured memory module for Conversational AI agents that combines the precision of database-style structural navigation with the flexibility of semantic relevance scoring. By organizing agent memory hierarchically rather than flattening it, it improves multi-turn task performance by up to 176.7% over flat Retrieval-Augmented Generation (RAG) baselines while using just 9.1% of the tokens required by standard in-context memory approaches.
What Problem Does This Paper Address?
As Conversational AI (ConvAI) agents transition from simple chatbots to complex assistants (e.g., managing travel itineraries, interactive to-do lists, or meal planning), they must maintain a long-term memory of evolving tasks. Currently, developers rely on two main paradigms, both of which have significant drawbacks:
- In-Context Memory: Appending the entire conversation history to the LLM prompt. This scales poorly, quickly hitting context-window limits, driving up token costs/latency, and degrading model reasoning ("lost in the middle" effects).
- Flat RAG: Storing memory as a flat collection of text chunks and retrieving them via vector similarity. This completely ignores the natural hierarchical structure of task data. For instance, if a user asks to "add a coffee break on the day that is packed with conference sessions," a flat RAG system might pull conference activities from Day 1 but mistakenly insert the coffee break into Day 3 because it cannot reason about which activities belong to which day.
Methods
The authors introduce Semantic XPath, which models an agent's memory as a rooted tree governed by a domain-specific schema (e.g., Itinerary → Version → Day → POI).
To query this tree, they propose an extension of the classic XML XPath query language, augmented with soft semantic matching capabilities. The query language consists of four main components:
- Axis Navigators (
/,//): Dictate how the tree is traversed (children vs. descendants). - Node Selectors: Filter by specific node types (e.g.,
Day,POI). - Positional Selectors (
[i]): Target specific indices (e.g., the third day of a trip). - Semantic Relevance Operators (
P): Instead of exact string matching, these operators compute a soft semantic score using either embedding-based cosine similarity (via Qwen3-Embedding-8B) or natural language entailment (via a BART-MNLI model).
Query Execution Pipeline
When a user makes a request, the system:
- Translates the natural language request into a Semantic XPath query.
- Executes the query recursively, maintaining a weighted set of candidate nodes.
- Aggregates lower-level semantic scores (e.g., averaging the "conference-ness" of individual POIs to score an entire Day node).
- Returns the highest-scoring subtree to the downstream LLM for final generation or state modification.
The authors also showcase SemanticXPath Chat, an end-to-end demo system that provides a visual interface for tracking the memory tree structure and step-by-step query execution scores.
Datasets
The approach was evaluated across three distinct simulated long-term ConvAI scenarios, each featuring a curated interaction set of 20 single-turn and 5 multi-turn complex conversations:
- Travel Itinerary: A 7-day plan mapping days to restaurants and points of interest (POIs) with descriptions, costs, and preferences.
- To-Do List: A task manager spanning 5 categories (work, household, etc.), split into projects and individual tasks with deadlines and priorities.
- Meal Kit Recommendation: A 7-day family meal plan mapping family members to daily meal times and specific recipes annotated with ingredients and nutrition facts.
Experiments were conducted using GPT-5 mini and Gemini-3 flash as the primary LLM backbones.
Key Insights and Ideas
- Compositional vs. Abstractive Hierarchies: While prior hierarchical RAG methods focus on abstractive trees (where higher nodes are lossy text summaries of child nodes), task-oriented agents benefit far more from compositional hierarchies (where each level represents a distinct structural entity, like an itinerary containing days, which contain activities).
- The Failure of Surface Similarity: Flat RAG fails because it lacks scoping. If a user asks about outdoor activities specifically on "Day 7" when it's raining, flat RAG retrieves outdoor activities from any day of the trip due to surface-level keyword matching, completely missing the temporal constraint.
- Robust Version Control: By treating
Versionas a structural node in the tree, Semantic XPath can effortlessly handle complex multi-turn modifications, such as retrieving deleted items from a previous turn's context without getting confused by the intervening conversation history.
Key Results
- Massive Accuracy Boost over Flat RAG: In multi-turn settings, Semantic XPath achieved an average task pass rate of 80.0% to 83.3% (depending on the LLM backbone), vastly outperforming Flat RAG, which hovered around a meager 26.7% pass rate due to its structural blindness.
- Substantial Token Savings: Semantic XPath achieved comparable accuracy to the full in-context memory baseline while consuming only 9.1% of the tokens.
- Turn-Insensitive Efficiency: As conversations progress over multiple turns, the token usage of the in-context method grows linearly/exponentially. In contrast, Semantic XPath maintains a flat, stable token consumption profile across turns because it filters out irrelevant subtrees before generation.
Limitations and Future Work
- Schema Dependency: The system relies on a predefined domain schema. Adapting Semantic XPath to highly open-ended, unstructured conversations where a rigid hierarchy cannot be easily defined remains an open challenge.
- No Factual Guarantees: While the module drastically improves retrieval relevance, it still feeds data into a generative LLM, meaning it cannot completely eliminate downstream hallucinations or reasoning errors inherited from the backbone model.
- Future Directions: The authors suggest exploring automated schema discovery and dynamic tree restructuring to make the system more adaptable to unpredictable user tasks.
Summary updated