Skip to content

Commit 7aaca82

Browse files
committed
Enable direct RAG
1 parent cab98f6 commit 7aaca82

7 files changed

Lines changed: 76 additions & 16 deletions

File tree

db/admin.cypher

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ RETURN count(*) AS droppedIndexes
1313

1414

1515

16-
CALL db.index.fulltext.queryNodes(`embabel-content-fulltext-index`, 'xy')
16+
CALL db.index.vector.queryNodes(`embabel-content-index`, 10, $embeddings)
1717
YIELD node AS chunk, score
1818
WHERE score >= $similarityThreshold
19+
RETURN chunk.text AS text, chunk.id AS id,
20+
score
21+
ORDER BY score DESC
22+
23+
CALL db.index.fulltext.queryNodes('embabel-content-fulltext-index', 'the PromptRunner interface')
24+
YIELD node AS chunk, score
25+
WHERE score >= .8
1926
RETURN chunk.text AS text, chunk.id AS id,
2027
score
2128
ORDER BY score DESC

db/clean.cypher

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Delete data
2+
// You have been warned!
3+
4+
MATCH (n)
5+
DETACH DELETE n;
6+
7+
DROP INDEX `embabel-content-fulltext-index`;
8+
9+
DROP INDEX `embabel-content-index`;
10+
11+
DROP INDEX `embabel-entity-fulltext-index`;
12+
13+
DROP INDEX `embabel-entity-index`;

src/main/java/com/embabel/guide/GuideAgentBot.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.embabel.agent.api.common.SomeOf;
1010
import com.embabel.agent.core.AgentPlatform;
1111
import com.embabel.agent.rag.pipeline.event.RagPipelineEvent;
12+
import com.embabel.agent.rag.tools.DualShotConfig;
1213
import com.embabel.chat.AssistantMessage;
1314
import com.embabel.chat.Chatbot;
1415
import com.embabel.chat.Conversation;
@@ -19,6 +20,7 @@
1920
import org.springframework.lang.Nullable;
2021

2122
import javax.validation.constraints.Null;
23+
import java.time.Duration;
2224
import java.util.Collections;
2325

2426
record ConversationOver(String why) {
@@ -55,11 +57,14 @@ ChatbotReturn respond(
5557
.ai()
5658
.withLlm(guideData.guideConfig().llm())
5759
.withReferences(guideData.references())
58-
.withRag(guideData.ragOptions().withListener(e -> {
59-
if (e instanceof RagPipelineEvent rpe) {
60-
context.updateProgress(rpe.getDescription());
61-
}
62-
}))
60+
.withRag(guideData.ragOptions()
61+
.withDesiredMaxLatency(Duration.ofMinutes(10))
62+
.withDualShot(new DualShotConfig(100))
63+
.withListener(e -> {
64+
if (e instanceof RagPipelineEvent rpe) {
65+
context.updateProgress(rpe.getDescription());
66+
}
67+
}))
6368
.withTemplate("guide_system")
6469
.respondWithSystemPrompt(conversation,
6570
guideData.templateModel(Collections.singletonMap("user",

src/main/java/com/embabel/guide/GuideData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,5 @@ public Map<String, Object> templateModel(Map<String, Object> extras) {
108108
n.put("persona", guideConfig.persona());
109109
return n;
110110
}
111+
111112
}

src/main/java/com/embabel/guide/GuideShell.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package com.embabel.guide;
22

3+
import com.embabel.agent.api.common.OperationContext;
34
import com.embabel.agent.event.logging.personality.severance.LumonColorPalette;
5+
import com.embabel.agent.rag.RagRequest;
6+
import com.embabel.agent.rag.SimpleRagResponseFormatter;
47
import com.embabel.agent.shell.TerminalServices;
58
import com.embabel.chat.Chatbot;
69
import org.springframework.shell.standard.ShellComponent;
710
import org.springframework.shell.standard.ShellMethod;
11+
import org.springframework.shell.standard.ShellOption;
812

913
import java.nio.file.Path;
14+
import java.time.Duration;
1015

1116
@ShellComponent
1217
public record GuideShell(
1318
TerminalServices terminalServices,
1419
Chatbot chatbot,
15-
GuideData guideData) {
20+
GuideData guideData,
21+
OperationContext context) {
1622

1723
@ShellMethod("talk to docs")
1824
public String talk() {
@@ -43,4 +49,20 @@ public String provision() {
4349
public String chunks() {
4450
return guideData.count() + " chunks in the database";
4551
}
52+
53+
@ShellMethod("rag query")
54+
public String rag(
55+
@ShellOption String query,
56+
@ShellOption(defaultValue = "10") int topK,
57+
@ShellOption(defaultValue = "0.2") double similarityThreshold) {
58+
var raw = context.ai().rag().search(
59+
RagRequest.query(query)
60+
.withTopK(topK)
61+
.withSimilarityThreshold(similarityThreshold)
62+
.withDesiredMaxLatency(Duration.ofMinutes(5))
63+
);
64+
var ragResponseFormatter = SimpleRagResponseFormatter.INSTANCE;
65+
return "RAG response: \n" + ragResponseFormatter.format(raw);
66+
}
67+
4668
}

src/main/resources/application.properties

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,37 @@ embabel.agent.rag.neo.uri=${NEO4J_URI:bolt://localhost:7687}
99
embabel.agent.rag.neo.username=${NEO4J_USERNAME:neo4j}
1010
embabel.agent.rag.neo.password=${NEO4J_PASSWORD:brahmsian}
1111

12+
embabel.agent.rag.neo.max-chunk-size=1500
13+
embabel.agent.rag.neo.overlap-size=200
14+
1215
# Packages that OGM should scan for entities
1316
#embabel.agent.rag.neo.packages=
1417

15-
#embabel.discord.token=${EMBABEL_TEAM_HELPER_DISCORD_TOKEN:null}
18+
embabel.discord.token=${EMBABEL_TEAM_HELPER_DISCORD_TOKEN:null}
1619

1720

18-
embabel.agent.rag.compression-llm.model=${guide.default-llm}
19-
embabel.agent.rag.reranking-llm.model=${guide.default-llm}
21+
embabel.agent.rag.compression-llm.model=${guide.rag-llm}
22+
embabel.agent.rag.reranking-llm.model=${guide.rag-llm}
2023

2124
# This is actually the default but it's good to show
2225
# How to change it
23-
embabel.models.default-embedding-model=nomic-embed-text:latest
26+
#embabel.models.default-embedding-model=nomic-embed-text:latest
27+
embabel.models.default-embedding-model=text-embedding-3-small
28+
2429

25-
guide.default-llm=qwen3:0.6b
30+
guide.rag-llm=gpt-4.1-nano
2631

2732
guide.persona=bible
2833
guide.top-k=10
29-
guide.similarity-threshold=0.2
30-
guide.llm.model=qwen3:4b
34+
guide.similarity-threshold=0.7
35+
guide.llm.model=gpt-4.1-mini
36+
#guide.llm.model=qwen3:4b
37+
3138

3239
embabel.shell.line-length=140
3340

34-
logging.level.com.embabel.agent.rag=INFO
41+
logging.level.com.embabel.agent.rag=INFO
42+
43+
logging.level.com.embabel.agent.rag.tools=DEBUG
44+
45+
logging.level.com.embabel.agent.rag.pipeline=DEBUG

src/main/resources/prompts/coding_style.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## Coding Style
22

33
Refer to this if you generate any code.
4-
TRY NOT TO GENERATE CODE BUT PULL FROM EXAMPLES.
4+
TRY NOT TO GENERATE CODE BUT PULL FROM EXAMPLES OR/AND DOCUMENTATION.
5+
CODE GENERATION IS A LAST RESORT.
56

67
- Use modern Java features like var, records, and switch expressions.
78
- Use multiline strings rather than concatenation.

0 commit comments

Comments
 (0)