ttchungc commited on
Commit
1158d40
·
verified ·
1 Parent(s): 0ea9d0a

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +194 -0
README.md ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - zh
6
+ base_model:
7
+ - Qwen/Qwen3-Embedding-4B
8
+ pipeline_tag: feature-extraction
9
+ library_name: transformers
10
+ tags:
11
+ - embedding
12
+ - retriever
13
+ - RAG
14
+ - Agentic
15
+ - Skills
16
+ ---
17
+ # InsightEmb (Learning Action-Intent Embeddings for Agentic Insight Retrieval)
18
+
19
+ [![Paper](https://img.shields.io/badge/Paper-arXiv%3A2608.04761-red)](https://arxiv.org/pdf/2608.04761)
20
+ [![Code](https://img.shields.io/badge/GitHub-InsightEmb-black?logo=github)](https://github.com/ttchungc/InsightEmb)
21
+ [![Project Page](https://img.shields.io/badge/Project-Page-blue)](https://ttchungc.github.io/projects/insightemb/)
22
+
23
+ **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.
24
+
25
+ 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.
26
+
27
+
28
+ For the complete training pipeline, insight-generation scripts, and end-to-end agent evaluation, see the [official GitHub repository](https://github.com/ttchungc/InsightEmb).
29
+
30
+ ---
31
+
32
+ ## ✨ Key Features
33
+
34
+ - **Progress-Oriented Retrieval**
35
+ Retrieves insights according to whether they can resolve the current bottleneck and advance the agent toward its goal.
36
+
37
+ - **Action-Intent Matching**
38
+ Connects concrete agent states with abstract, procedurally useful rules rather than relying only on topical overlap.
39
+
40
+ - **Math-Only Retriever Training**
41
+ Learns transferable retrieval geometry from mathematical problems and reasoning trajectories, without target-environment retriever optimization.
42
+
43
+ - **Two-Stage Contrastive Curriculum**
44
+ - **Situation-to-Insight Matching:** aligns problems and intermediate reasoning states with abstract heuristic rules.
45
+ - **Situation-to-Experience Matching:** groups different-looking situations that require the same underlying strategy.
46
+
47
+ - **Partial-Trajectory Supervision**
48
+ Uses truncated reasoning traces to train retrieval from intermediate states, improving sensitivity to evolving procedural bottlenecks.
49
+
50
+ - **Cross-Domain Transfer**
51
+ Evaluated on ALFWorld, WebShop, ScienceWorld, and SRA-Bench, with consistent gains over the base embedder and strong reasoning-oriented retrievers.
52
+
53
+ ---
54
+
55
+ ## 🚀 Quick Start
56
+
57
+ ### Installation
58
+
59
+ ```bash
60
+ pip install torch transformers>=4.53.0
61
+ ```
62
+
63
+ ### 1) Load the Model
64
+
65
+ Replace `YOUR_HF_NAMESPACE/InsightEmb` with the model repository ID.
66
+
67
+ ```python
68
+ import torch
69
+ import torch.nn.functional as F
70
+ from transformers import AutoModel, AutoTokenizer
71
+
72
+ MODEL_ID = "YOUR_HF_NAMESPACE/InsightEmb"
73
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
74
+
75
+ # InsightEmb is initialized from Qwen3-Embedding-4B.
76
+ tokenizer = AutoTokenizer.from_pretrained(
77
+ "Qwen/Qwen3-Embedding-4B",
78
+ trust_remote_code=True,
79
+ padding_side="left",
80
+ )
81
+
82
+ model = AutoModel.from_pretrained(
83
+ MODEL_ID,
84
+ trust_remote_code=True,
85
+ torch_dtype=torch.bfloat16,
86
+ attn_implementation="flash_attention_2",
87
+ ).to(DEVICE).eval()
88
+ ```
89
+
90
+ ### 2) Encode Text
91
+
92
+ InsightEmb uses last-token pooling followed by L2 normalization.
93
+
94
+ ```python
95
+ def last_token_pool(last_hidden_states, attention_mask):
96
+ left_padding = attention_mask[:, -1].sum() == attention_mask.shape[0]
97
+ if left_padding:
98
+ return last_hidden_states[:, -1]
99
+
100
+ sequence_lengths = attention_mask.sum(dim=1) - 1
101
+ batch_size = last_hidden_states.shape[0]
102
+ return last_hidden_states[
103
+ torch.arange(batch_size, device=last_hidden_states.device),
104
+ sequence_lengths,
105
+ ]
106
+
107
+
108
+ @torch.inference_mode()
109
+ def encode(texts, max_length=8192):
110
+ inputs = tokenizer(
111
+ texts,
112
+ padding=True,
113
+ truncation=True,
114
+ max_length=max_length,
115
+ return_tensors="pt",
116
+ ).to(DEVICE)
117
+
118
+ outputs = model(**inputs)
119
+ embeddings = last_token_pool(
120
+ outputs.last_hidden_state,
121
+ inputs["attention_mask"],
122
+ )
123
+ return F.normalize(embeddings, p=2, dim=1)
124
+ ```
125
+
126
+ ### 3) Retrieve Insights for an Agent State
127
+
128
+ Queries should include a retrieval instruction. Candidate insights are encoded directly.
129
+
130
+ ```python
131
+ retrieval_instruction = (
132
+ "Given the current agent state, retrieve insights that resolve the "
133
+ "current bottleneck and help the agent make progress toward its goal"
134
+ )
135
+
136
+ agent_state = """
137
+ Goal: buy a light-grey dining set under $250.
138
+ History: searched twice and browsed several result pages.
139
+ Observation: many partially matching products are visible, but none selected.
140
+ """
141
+
142
+ query = f"Instruct: {retrieval_instruction}\nQuery:{agent_state}"
143
+
144
+ insights = [
145
+ "Keep refining the query until an exact product appears.",
146
+ "Include all critical attributes in the search, then select the required variant before purchasing.",
147
+ "Browse more result pages before committing to a product.",
148
+ ]
149
+
150
+ query_embedding = encode([query])
151
+ insight_embeddings = encode(insights)
152
+
153
+ scores = (query_embedding @ insight_embeddings.T).squeeze(0)
154
+ top_indices = torch.topk(scores, k=2).indices.tolist()
155
+
156
+ for rank, index in enumerate(top_indices, start=1):
157
+ print(f"Insight {rank}: {insights[index]}")
158
+ ```
159
+
160
+ For dynamic retrieval after every environment step, see the [ALFWorld, WebShop, and ScienceWorld implementations](https://github.com/ttchungc/InsightEmb).
161
+
162
+ ---
163
+
164
+ ## 🎯 Intended Use
165
+
166
+ InsightEmb is designed for retrieval settings where relevance is primarily **procedural or structural**, including:
167
+
168
+ - agent memory and insight retrieval
169
+ - state-aware retrieval for interactive agents
170
+ - skill and strategy retrieval
171
+ - reasoning-intensive retrieval
172
+ - retrieval of abstract rules with limited lexical overlap
173
+
174
+ It can be used as a bi-encoder retriever or as the dense component of a hybrid retrieval pipeline.
175
+
176
+ ---
177
+
178
+ ## 📜 Citation
179
+
180
+
181
+
182
+ If you find this work useful, please cite:
183
+
184
+ ```bibtex
185
+ @misc{chung2026insightemblearningactionintentembeddings,
186
+ title={InsightEmb: Learning Action-Intent Embeddings for Agentic Insight Retrieval},
187
+ author={Tsz Ting Chung and Jiangnan Li and Jie Zhou and Mo Yu},
188
+ year={2026},
189
+ eprint={2608.04761},
190
+ archivePrefix={arXiv},
191
+ primaryClass={cs.CL},
192
+ url={https://arxiv.org/abs/2608.04761},
193
+ }
194
+ ```