File size: 6,344 Bytes
1158d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
---
license: apache-2.0
language:
- en
- zh
base_model:
- Qwen/Qwen3-Embedding-4B
pipeline_tag: feature-extraction
library_name: transformers
tags:
- embedding
- retriever
- RAG
- Agentic
- Skills
---
# InsightEmb (Learning Action-Intent Embeddings for Agentic Insight Retrieval)

[![Paper](https://img.shields.io/badge/Paper-arXiv%3A2608.04761-red)](https://arxiv.org/pdf/2608.04761)
[![Code](https://img.shields.io/badge/GitHub-InsightEmb-black?logo=github)](https://github.com/ttchungc/InsightEmb)
[![Project Page](https://img.shields.io/badge/Project-Page-blue)](https://ttchungc.github.io/projects/insightemb/)

**InsightEmb** is an embedding model for **agentic insight retrieval**. It retrieves abstract rules and strategies that resolve an agent's current procedural bottleneck and enable the next useful action.

Unlike conventional dense retrieval, which mainly captures semantic similarity, InsightEmb learns **progress-oriented action-intent matching**. The model is trained on mathematical reasoning data and transfers to interactive agent environments without environment-specific retriever fine-tuning.


For the complete training pipeline, insight-generation scripts, and end-to-end agent evaluation, see the [official GitHub repository](https://github.com/ttchungc/InsightEmb).

---

## ✨ Key Features

- **Progress-Oriented Retrieval**  
  Retrieves insights according to whether they can resolve the current bottleneck and advance the agent toward its goal.

- **Action-Intent Matching**  
  Connects concrete agent states with abstract, procedurally useful rules rather than relying only on topical overlap.

- **Math-Only Retriever Training**  
  Learns transferable retrieval geometry from mathematical problems and reasoning trajectories, without target-environment retriever optimization.

- **Two-Stage Contrastive Curriculum**
  - **Situation-to-Insight Matching:** aligns problems and intermediate reasoning states with abstract heuristic rules.
  - **Situation-to-Experience Matching:** groups different-looking situations that require the same underlying strategy.

- **Partial-Trajectory Supervision**  
  Uses truncated reasoning traces to train retrieval from intermediate states, improving sensitivity to evolving procedural bottlenecks.

- **Cross-Domain Transfer**  
  Evaluated on ALFWorld, WebShop, ScienceWorld, and SRA-Bench, with consistent gains over the base embedder and strong reasoning-oriented retrievers.

---

## 🚀 Quick Start

### Installation

```bash
pip install torch transformers>=4.53.0
```

### 1) Load the Model

Replace `YOUR_HF_NAMESPACE/InsightEmb` with the model repository ID.

```python
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer

MODEL_ID = "YOUR_HF_NAMESPACE/InsightEmb"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"

# InsightEmb is initialized from Qwen3-Embedding-4B.
tokenizer = AutoTokenizer.from_pretrained(
    "Qwen/Qwen3-Embedding-4B",
    trust_remote_code=True,
    padding_side="left",
)

model = AutoModel.from_pretrained(
    MODEL_ID,
    trust_remote_code=True,
    torch_dtype=torch.bfloat16,
    attn_implementation="flash_attention_2",
).to(DEVICE).eval()
```

### 2) Encode Text

InsightEmb uses last-token pooling followed by L2 normalization.

```python
def last_token_pool(last_hidden_states, attention_mask):
    left_padding = attention_mask[:, -1].sum() == attention_mask.shape[0]
    if left_padding:
        return last_hidden_states[:, -1]

    sequence_lengths = attention_mask.sum(dim=1) - 1
    batch_size = last_hidden_states.shape[0]
    return last_hidden_states[
        torch.arange(batch_size, device=last_hidden_states.device),
        sequence_lengths,
    ]


@torch.inference_mode()
def encode(texts, max_length=8192):
    inputs = tokenizer(
        texts,
        padding=True,
        truncation=True,
        max_length=max_length,
        return_tensors="pt",
    ).to(DEVICE)

    outputs = model(**inputs)
    embeddings = last_token_pool(
        outputs.last_hidden_state,
        inputs["attention_mask"],
    )
    return F.normalize(embeddings, p=2, dim=1)
```

### 3) Retrieve Insights for an Agent State

Queries should include a retrieval instruction. Candidate insights are encoded directly.

```python
retrieval_instruction = (
    "Given the current agent state, retrieve insights that resolve the "
    "current bottleneck and help the agent make progress toward its goal"
)

agent_state = """
Goal: buy a light-grey dining set under $250.
History: searched twice and browsed several result pages.
Observation: many partially matching products are visible, but none selected.
"""

query = f"Instruct: {retrieval_instruction}\nQuery:{agent_state}"

insights = [
    "Keep refining the query until an exact product appears.",
    "Include all critical attributes in the search, then select the required variant before purchasing.",
    "Browse more result pages before committing to a product.",
]

query_embedding = encode([query])
insight_embeddings = encode(insights)

scores = (query_embedding @ insight_embeddings.T).squeeze(0)
top_indices = torch.topk(scores, k=2).indices.tolist()

for rank, index in enumerate(top_indices, start=1):
    print(f"Insight {rank}: {insights[index]}")
```

For dynamic retrieval after every environment step, see the [ALFWorld, WebShop, and ScienceWorld implementations](https://github.com/ttchungc/InsightEmb).

---

## 🎯 Intended Use

InsightEmb is designed for retrieval settings where relevance is primarily **procedural or structural**, including:

- agent memory and insight retrieval
- state-aware retrieval for interactive agents
- skill and strategy retrieval
- reasoning-intensive retrieval
- retrieval of abstract rules with limited lexical overlap

It can be used as a bi-encoder retriever or as the dense component of a hybrid retrieval pipeline.

---

## 📜 Citation



If you find this work useful, please cite:

```bibtex
@misc{chung2026insightemblearningactionintentembeddings,
      title={InsightEmb: Learning Action-Intent Embeddings for Agentic Insight Retrieval}, 
      author={Tsz Ting Chung and Jiangnan Li and Jie Zhou and Mo Yu},
      year={2026},
      eprint={2608.04761},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2608.04761}, 
}
```