Skip to content

Commit 7e32e35

Browse files
authored
Improve prompts and context (#3)
1 parent 36c6a8d commit 7e32e35

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/pinecone.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct AssistantContext {
3434

3535
#[derive(Debug, Deserialize)]
3636
pub struct AssistantContextResponse {
37-
pub snippets: serde_json::Value,
37+
pub snippets: Vec<serde_json::Value>,
3838
pub usage: serde_json::Value,
3939
}
4040

@@ -108,7 +108,7 @@ mod tests {
108108
.mock("POST", "/assistant/chat/test-assistant/context")
109109
.with_status(200)
110110
.with_header("content-type", "application/json")
111-
.with_body(r#"{"snippets": [{"text": "This is a test response"}], "usage": {"total_tokens": 100}}"#)
111+
.with_body(r#"{"snippets": [{"text": "snippet 1"}, {"text": "snippet 2"}], "usage": {"total_tokens": 100}}"#)
112112
.create();
113113

114114
let client = PineconeClient::new("test-api-key".to_string(), server.url());
@@ -119,7 +119,8 @@ mod tests {
119119

120120
mock.assert();
121121
let response = result.unwrap();
122-
assert_eq!(response.snippets[0]["text"], "This is a test response");
122+
assert_eq!(response.snippets[0]["text"], "snippet 1");
123+
assert_eq!(response.snippets[1]["text"], "snippet 2");
123124
}
124125

125126
#[tokio::test]

src/router.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::config::Config;
22
use crate::pinecone::{PineconeClient, PineconeError};
3+
use mcp_server::router::CapabilitiesBuilder;
34
use mcp_spec::content::Content;
45
use mcp_spec::handler::{PromptError, ResourceError, ToolError};
56
use mcp_spec::prompt::Prompt;
67
use mcp_spec::{protocol::ServerCapabilities, resource::Resource, tool::Tool};
7-
use mcp_server::router::CapabilitiesBuilder;
88
use serde_json::Value;
99
use std::future::Future;
1010
use std::pin::Pin;
@@ -52,21 +52,24 @@ impl PineconeAssistantRouter {
5252
client,
5353
tools: vec![Tool::new(
5454
TOOL_ASSISTANT_CONTEXT.to_string(),
55-
"Retrieve context snippets from a Pinecone assistant knowledge base".to_string(),
55+
"Retrieves relevant document snippets from your Pinecone Assistant knowledge base. \
56+
Returns an array of text snippets from the most relevant documents. \
57+
You can use the 'top_k' parameter to control result count (default: 15). \
58+
Recommended top_k: a few (5-8) for simple/narrow queries, 10-20 for complex/broad topics.".to_string(),
5659
serde_json::json!({
5760
"type": "object",
5861
"properties": {
5962
PARAM_ASSISTANT_NAME: {
6063
"type": "string",
61-
"description": "Name of the Pinecone assistant"
64+
"description": "Name of an existing Pinecone assistant"
6265
},
6366
PARAM_QUERY: {
6467
"type": "string",
65-
"description": "The query to use for generating context."
68+
"description": "The query to retrieve context for."
6669
},
6770
PARAM_TOP_K: {
6871
"type": "integer",
69-
"description": "Number of context snippets to return. Default is 15."
72+
"description": "The number of context snippets to retrieve. Defaults to 15."
7073
}
7174
},
7275
"required": [PARAM_ASSISTANT_NAME, PARAM_QUERY]
@@ -100,7 +103,11 @@ impl PineconeAssistantRouter {
100103
.await?;
101104

102105
tracing::info!("Successfully received response from Pinecone API");
103-
Ok(vec![Content::text(response.snippets.to_string())])
106+
Ok(response
107+
.snippets
108+
.iter()
109+
.map(|snippet| Content::text(snippet.to_string()))
110+
.collect())
104111
}
105112
}
106113

@@ -111,14 +118,9 @@ impl mcp_server::Router for PineconeAssistantRouter {
111118

112119
fn instructions(&self) -> String {
113120
format!(
114-
"This server provides tools to interact with Pinecone's Assistant API. \
115-
The {TOOL_ASSISTANT_CONTEXT} tool allows you to retrieve relevant context snippets from given knowledge base assistants. \
116-
Returned value structure: \
117-
An array of relevant document snippets, each containing: \
118-
- content: The text content of the snippet \
119-
- score: A relevance score (float) \
120-
- reference: Source information including document ID and location \
121-
You can tune the number of returned snippets by setting the `top_k` parameter."
121+
"This server connects to an existing Pinecone Assistant,\
122+
a RAG system for retrieving relevant document snippets. \
123+
Use the {TOOL_ASSISTANT_CONTEXT} tool to access contextual information from its knowledge base"
122124
)
123125
}
124126

0 commit comments

Comments
 (0)