Skip to content

Commit 5f1c4d2

Browse files
committed
Several small fixes
1 parent 7d2bdd8 commit 5f1c4d2

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121

2222
@mcp.tool(structured_output=True)
2323
def retrieve_docs_tool(query: str) -> RetrieveDocsOutput:
24-
"""Return structured retrieval results as {docs: [...]}."""
24+
"""
25+
Fetch prioritized chunks from your RAG store—documentation, how-tos, tutorials and articles—
26+
based on a single search query.
27+
"""
2528
return retrieve_docs(query)
2629

2730
# Template for future tools:

tools/rag_retrieve.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
from typing import List
3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
44

55
from openai import OpenAI
66
from pinecone import Pinecone
@@ -18,15 +18,18 @@
1818

1919
# ====== Pydantic models ======
2020
class DocItem(BaseModel):
21-
"""Single retrieved document item."""
22-
source: str
23-
text: str
24-
score: float
21+
"""Single retrieved chunk from the RAG knowledge base."""
22+
source: str = Field(..., description="Chunk origin (e.g. docs, howto, tutorial).")
23+
text: str = Field(..., description="Retrieved text snippet.")
24+
score: float = Field(..., description="Similarity score (higher = more relevant).")
2525

2626

2727
class RetrieveDocsOutput(BaseModel):
28-
"""Structured response containing a list of retrieved document items."""
29-
docs: List[DocItem]
28+
"""List of retrieved chunks sorted by relevance."""
29+
docs: List[DocItem] = Field(
30+
default_factory=list,
31+
description="Relevant chunks returned from the RAG store."
32+
)
3033

3134

3235
# ====== Initialization ======
@@ -73,9 +76,8 @@ def _get_embedding(text: str) -> List[float]:
7376

7477
def retrieve_docs(query: str) -> RetrieveDocsOutput:
7578
"""
76-
Query Pinecone using an OpenAI embedding for the given query.
77-
Returns a structured object:
78-
{ "docs": [ { "source": str, "text": str, "score": float }, ... ] }
79+
Fetch prioritized chunks from your RAG store—documentation, how-tos, tutorials and articles—
80+
based on a single search query.
7981
"""
8082
vec = _get_embedding(query)
8183
items: List[DocItem] = []
@@ -100,4 +102,11 @@ def retrieve_docs(query: str) -> RetrieveDocsOutput:
100102

101103
# Sort results by descending score
102104
items.sort(key=lambda d: -d.score)
103-
return RetrieveDocsOutput(docs=items)
105+
output = RetrieveDocsOutput(docs=items)
106+
107+
print(f"[retrieve_docs] Query: {query!r}")
108+
print(f"[retrieve_docs] Retrieved {len(items)} document(s):")
109+
for i, d in enumerate(items, 1):
110+
print(f" {i}. [{d.source}] score={d.score:.4f}{d.text[:100]!r}")
111+
112+
return output

0 commit comments

Comments
 (0)