You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/llama-nexus/mcp/agentic-search.md
+287-1Lines changed: 287 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,290 @@ sidebar_position: 2
4
4
5
5
# Agentic Search
6
6
7
-
To be add
7
+
With its support for MCP servers, we can support "agentic search" from llama nexus. That is to support transparent knowledge base search via the `/chat/completions` API. There is no need for the llama nexus client to handle any tool call or MCP. It works like this:
8
+
9
+
A `search()` tool is registered with llama nexus from an MCP server. When the user asks a question via the `/chat/completions` API, llama nexus knows to use the `search()` tool internally with its downstream LLM, and respond based on the search result. The user automagically gets a correct response to its `/chat/completions` request without needing to know anything about MCP tool calls or the knowledge base!
10
+
11
+
In this tutorial, you will learn how to set two databases from the same source materials. One is a Qdrant vector database to support semantic search, and the other is a TiDB relational database to support keyword search. We could improve the search accuracy by searching both databases. We will cover
12
+
13
+
* How to set up the databases
14
+
* How to add data and index to the databases
15
+
* How to set up the agentic search MCP server that provides the `search()` tool
16
+
* How to add the agentic search MCP server to llama nexus
17
+
* How to test the fina llama nexus set up
18
+
19
+
## Prepare databases
20
+
21
+
We use Qdrant and TiDB to store the knowledge content in vector and full text formats respectively. They enable semantic and keywords searches of the knowledge base.
22
+
23
+
### Qdrant cloud
24
+
25
+
Create a Qdrant cloud account here: https://cloud.qdrant.io/
26
+
27
+
Create a new cluster in any region.
28
+
29
+
Click open the cluster name, go to the API Keys tab to get an API key.
30
+
31
+

32
+
33
+
Open the Dashboard or Cluster UI for this cluster by clicking on the `...` button next to the cluster name. The base URL of the Dashboard is the base URL for connecting to the cluster.
#### Optional: create your own collection in Qdrant
40
+
41
+
> This is optional because the system will automatically create this vector collection if it does not exist. If the collection already exists, the system will write new data into the collection.
42
+
43
+
In the Console tab to the left of the Dashboard page, type in the following API request to create a new vector collection named `myPoints`.
44
+
45
+
```
46
+
PUT collections/myPoints
47
+
{
48
+
"vectors": {
49
+
"size": 1536,
50
+
"distance": "Cosine"
51
+
}
52
+
}
53
+
```
54
+
55
+
### TiDB cloud
56
+
57
+
Create an TiDB cloud account here: https://tidbcloud.com/
58
+
59
+
Create a new cluster in the Singapore (`ap-southeast-1`) region.
60
+
61
+
Click open the "Overview" tab, and click on the "Connect" button. Write down the following database connection string.
The `<PASSWORD>` can be revealed once with the Reset Password link above the connection string display.
68
+
69
+
#### Optional: create your own database table in TiDB
70
+
71
+
> This is optional because the system will automatically create this table if it does not exist. If the table already exists, the system will write new data into the table.
72
+
73
+
Click open the "SQL Editor" tab. Enter a SQL command and hit the "Run" button to create a new database.
74
+
75
+
```
76
+
CREATE DATABASE myDB;
77
+
```
78
+
79
+
Then, create a table in `myDB` based on our schema.
80
+
81
+
```
82
+
USE myDB;
83
+
84
+
CREATE TABLE myItems (
85
+
id INT NOT NULL AUTO_INCREMENT,
86
+
title TEXT NOT NULL,
87
+
content TEXT NOT NULL,
88
+
FULLTEXT INDEX (content) WITH PARSER MULTILINGUAL
89
+
);
90
+
```
91
+
92
+
Click open the "Overview" tab, and click on the "Connect" button. Write down the following database connection string.
tar xvf cardea-mcp-servers-unknown-linux-gnu-x86_64.tar
182
+
```
183
+
184
+
> Download for your platform: https://github.com/cardea-mcp/cardea-mcp-servers/releases/tag/0.7.0/
185
+
186
+
Set the environment variables. The `TIDB_CONNECTION` is the TiDB connection URL from above, which includes the username and password. The `QDRANT_BASE_URL` is the Qdrant cluster connection URL, and it defaults to `http://localhost:6333`.
Start the agentic search MCP server with database connection parameters. Make sure that you adjust the `--search-tool-desc` and `--search-tool-param-desc` to describe the search queries that can be performed for this database.
197
+
198
+
```
199
+
nohup ./cardea-agentic-search-mcp-server \
200
+
--socket-addr 127.0.0.1:9096 \
201
+
--transport stream-http \
202
+
--search-tool-desc "You MUST call the search() tool before you answer any factual question. Create a question from the user query and relevant context, and pass the question as a string to the tool call." \
203
+
--search-tool-param-desc "The question to search for answers." \
Use the command line to request the `/chat/completions` API endpoint directly.
286
+
287
+
```
288
+
curl -X POST http://localhost:9095/v1/chat/completions \
289
+
-H 'accept: application/json' \
290
+
-H 'Content-Type: application/json' \
291
+
-d '{"messages":[{"role":"system", "content": "If the user asks a question, you MUST use the search() tool call and pass in a list of search keywords to search for relevant information and then form your response based on the search results."},{"role":"user", "content": "What prevents cancer?"}]}'
0 commit comments