Skip to content

Commit df80158

Browse files
authored
Changes to RAG page (#1621)
1 parent 0e0fbca commit df80158

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

pgml-dashboard/src/components/code_editor/editor/editor_controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ export default class extends Controller {
9595
};
9696
}
9797

98+
onQuestionChange() {
99+
let transaction = this.editor.state.update({
100+
changes: {
101+
from: 0,
102+
to: this.editor.state.doc.length,
103+
insert: generateSql(
104+
this.currentTask(),
105+
this.currentModel(),
106+
this.questionInputTarget.value,
107+
),
108+
},
109+
});
110+
this.editor.dispatch(transaction);
111+
}
112+
98113
currentTask() {
99114
return this.hasTaskTarget ? this.taskTarget.value : this.defaultTaskValue;
100115
}

pgml-dashboard/src/components/code_editor/editor/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct Editor {
1414
is_editable: bool,
1515
run_on_visible: bool,
1616
content: Option<String>,
17+
default_result: String,
1718
}
1819

1920
impl Editor {
@@ -29,6 +30,7 @@ impl Editor {
2930
is_editable: true,
3031
run_on_visible: false,
3132
content: None,
33+
default_result: "AI is going to change the world!".to_string(),
3234
}
3335
}
3436

@@ -44,10 +46,11 @@ impl Editor {
4446
is_editable: false,
4547
run_on_visible: false,
4648
content: None,
49+
default_result: "Unified RAG is...".to_string(),
4750
}
4851
}
4952

50-
pub fn new_custom(content: &str) -> Editor {
53+
pub fn new_custom(content: &str, default_result: &str) -> Editor {
5154
Editor {
5255
show_model: false,
5356
show_task: false,
@@ -59,9 +62,15 @@ impl Editor {
5962
is_editable: true,
6063
run_on_visible: false,
6164
content: Some(content.to_owned()),
65+
default_result: default_result.to_string(),
6266
}
6367
}
6468

69+
pub fn set_default_result(mut self, default_result: &str) -> Editor {
70+
self.default_result = default_result.to_string();
71+
self
72+
}
73+
6574
pub fn set_show_model(mut self, show_model: bool) -> Self {
6675
self.show_model = show_model;
6776
self

pgml-dashboard/src/components/code_editor/editor/template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<div class="d-flex flex-row position-relative pt-3 pb-3 ps-4 pe-4">
114114
<div class="d-flex align-items-lg-center gap-lg-3 flex-fill flex-column flex-lg-row question-input">
115115
<label class=""><strong class="text-uppercase text-white">Question:</strong></label>
116-
<input type="text" class="form-control" placeholder="Ask a question about PGML" data-code-editor-editor-target="questionInput">
116+
<input type="text" class="form-control" placeholder="Ask a question about PGML" data-code-editor-editor-target="questionInput" data-action="code-editor-editor#onQuestionChange">
117117
</div>
118118
<% if btn_location == "question-header" {%>
119119
<div class="d-flex align-items-center">
@@ -156,7 +156,7 @@
156156
</div>
157157

158158
<div id="editor-play-result-stream" data-code-editor-editor-target="resultStream">
159-
AI is going to change the world!
159+
<%= default_result %>
160160
</div>
161161

162162
</div>

pgml-dashboard/static/js/utilities/demo.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const generateSql = (task, model, userInput) => {
44
let extraTaskArgs = generateTaskArgs(task, model, "sql");
55

66
if (!userInput && task == "embedded-query") {
7-
userInput ="What is Postgres?"
7+
userInput ="What is Unified RAG?"
88
}
99

1010
let argsOutput = "";
@@ -28,23 +28,29 @@ export const generateSql = (task, model, userInput) => {
2828
);`;
2929
} else if (task === "embedded-query") {
3030
return `WITH embedded_query AS (
31-
SELECT pgml.embed('mixedbread-ai/mxbai-embed-large-v1', 'What is Postgres?', '{"prompt": "Represent this sentence for searching relevant passages: "}'::JSONB)::vector embedding
31+
SELECT pgml.embed(
32+
'mixedbread-ai/mxbai-embed-large-v1',
33+
'${userInput}',
34+
'{"prompt": "Represent this sentence for searching relevant passages: "}'::JSONB
35+
)::vector embedding
3236
),
3337
context_query AS (
34-
SELECT chunks.chunk FROM chunks
35-
INNER JOIN embeddings ON embeddings.chunk_id = chunks.id
36-
ORDER BY embeddings.embedding <=> (SELECT embedding FROM embedded_query)
37-
LIMIT 1
38+
SELECT string_agg(chunk, '\n\n') as context FROM (
39+
SELECT chunks.chunk FROM chunks
40+
INNER JOIN embeddings ON embeddings.chunk_id = chunks.id
41+
ORDER BY embeddings.embedding <=> (SELECT embedding FROM embedded_query)
42+
LIMIT 5
43+
) sub
3844
)
3945
SELECT
4046
pgml.transform(
4147
task => '{
4248
"task": "conversational",
43-
"model": "meta-llama/Meta-Llama-3.1-8B-Instruct"
49+
"model": "meta-llama/Meta-Llama-3.1-70B-Instruct"
4450
}'::jsonb,
45-
inputs => ARRAY['{"role": "system", "content": "You are a friendly and helpful chatbot."}'::jsonb, jsonb_build_object('role', 'user', 'content', replace('Given the context answer the following question. ${userInput}? Context:\n{CONTEXT}', '{CONTEXT}', chunk))],
51+
inputs => ARRAY['{"role": "system", "content": "You are a question answering chatbot. Answer the users question using the provided context."}'::jsonb, jsonb_build_object('role', 'user', 'content', replace('Question:\n\n${userInput}\n\nContext:\n\n{CONTEXT}', '{CONTEXT}', context))],
4652
args => '{
47-
"max_new_tokens": 100
53+
"max_new_tokens": 512
4854
}'::jsonb
4955
)
5056
FROM context_query;`

0 commit comments

Comments
 (0)