Spaces:
Runtime error
Runtime error
cleanup; readme
Browse files- README.md +74 -0
- app/main.py +2 -2
README.md
CHANGED
@@ -8,3 +8,77 @@ pinned: false
|
|
8 |
---
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
|
11 |
+
# ChatFed Retriever - MCP Server
|
12 |
+
|
13 |
+
A semantic document retrieval and reranking service designed for ChatFed RAG (Retrieval-Augmented Generation) pipelines. This module serves as an **MCP (Model Context Protocol) server** that retrieves semantically similar documents from vector databases with optional cross-encoder reranking.
|
14 |
+
|
15 |
+
## MCP Endpoint
|
16 |
+
|
17 |
+
The main MCP function is `retrieve_mcp` which provides a top_k retrieval and reranking function when properly connected to an external vector database.
|
18 |
+
|
19 |
+
**Parameters**:
|
20 |
+
- `query` (str, required): The search query text
|
21 |
+
- `reports_filter` (str, optional): Comma-separated list of specific report filenames
|
22 |
+
- `sources_filter` (str, optional): Filter by document source type
|
23 |
+
- `subtype_filter` (str, optional): Filter by document subtype
|
24 |
+
- `year_filter` (str, optional): Comma-separated list of years to filter by
|
25 |
+
|
26 |
+
**Returns**: List of dictionaries containing:
|
27 |
+
- `answer`: Document content
|
28 |
+
- `answer_metadata`: Document metadata
|
29 |
+
- `score`: Relevance score [disabled when reranker used]
|
30 |
+
|
31 |
+
|
32 |
+
```python
|
33 |
+
from gradio_client import Client
|
34 |
+
|
35 |
+
client = Client("https://mtyrrell-chatfed-retriever.hf.space/")
|
36 |
+
result = client.predict(
|
37 |
+
query="...",
|
38 |
+
reports_filter="",
|
39 |
+
sources_filter="",
|
40 |
+
subtype_filter="",
|
41 |
+
year_filter="",
|
42 |
+
api_name="/retrieve_mcp"
|
43 |
+
)
|
44 |
+
print(result)
|
45 |
+
```
|
46 |
+
|
47 |
+
## ⚙️ Configuration
|
48 |
+
|
49 |
+
### Vector Store Configuration
|
50 |
+
1. Set your data source according to the provider
|
51 |
+
2. Set the embedding model to match the data source
|
52 |
+
3. Set the retriever parameters
|
53 |
+
4. [Optional] Set the reranker parameters
|
54 |
+
5. Run the app:
|
55 |
+
|
56 |
+
```bash
|
57 |
+
docker build -t chatfed-retriever .
|
58 |
+
docker run -p 7860:7860 chatfed-retriever
|
59 |
+
```
|
60 |
+
|
61 |
+
6. Test connection
|
62 |
+
|
63 |
+
```python
|
64 |
+
from gradio_client import Client
|
65 |
+
|
66 |
+
def test_retrieve_mcp():
|
67 |
+
client = Client("ENTER CONTAINER URL")
|
68 |
+
|
69 |
+
# Make a simple query
|
70 |
+
result = client.predict(
|
71 |
+
query="Return all audit reports relating to climate change?",
|
72 |
+
reports_filter="",
|
73 |
+
sources_filter="",
|
74 |
+
subtype_filter="",
|
75 |
+
year_filter="",
|
76 |
+
api_name="/retrieve_mcp"
|
77 |
+
)
|
78 |
+
|
79 |
+
print(result)
|
80 |
+
|
81 |
+
if __name__ == "__main__":
|
82 |
+
test_retrieve_mcp()
|
83 |
+
```
|
84 |
+
|
app/main.py
CHANGED
@@ -93,8 +93,8 @@ def retrieve_ui(query, reports_filter="", sources_filter="", subtype_filter="",
|
|
93 |
|
94 |
# Create the Gradio interface with Blocks to support both UI and MCP
|
95 |
with gr.Blocks() as ui:
|
96 |
-
gr.Markdown("#
|
97 |
-
gr.Markdown("Retrieves semantically similar documents from vector database. Intended for use in RAG pipelines as an MCP server.")
|
98 |
|
99 |
with gr.Row():
|
100 |
with gr.Column():
|
|
|
93 |
|
94 |
# Create the Gradio interface with Blocks to support both UI and MCP
|
95 |
with gr.Blocks() as ui:
|
96 |
+
gr.Markdown("# ChatFed Retrieval/Reranker Module")
|
97 |
+
gr.Markdown("Retrieves semantically similar documents from vector database and reranks. Intended for use in RAG pipelines as an MCP server with other ChatFed modules.")
|
98 |
|
99 |
with gr.Row():
|
100 |
with gr.Column():
|