mirror of
https://github.com/lancedb/lancedb.git
synced 2025-12-23 05:19:58 +00:00
Compare commits
8 Commits
python-v0.
...
docs/mcp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f8950653a | ||
|
|
d071268058 | ||
|
|
3f99313ec6 | ||
|
|
8cb1665708 | ||
|
|
6c6966600c | ||
|
|
2e170c3c7b | ||
|
|
fd92e651d1 | ||
|
|
c298482ee1 |
@@ -1,5 +1,5 @@
|
||||
[tool.bumpversion]
|
||||
current_version = "0.19.0-beta.4"
|
||||
current_version = "0.19.0-beta.5"
|
||||
parse = """(?x)
|
||||
(?P<major>0|[1-9]\\d*)\\.
|
||||
(?P<minor>0|[1-9]\\d*)\\.
|
||||
|
||||
@@ -162,6 +162,7 @@ nav:
|
||||
- Choosing right query type: guides/tuning_retrievers/1_query_types.md
|
||||
- Reranking: guides/tuning_retrievers/2_reranking.md
|
||||
- Embedding fine-tuning: guides/tuning_retrievers/3_embed_tuning.md
|
||||
- Build MCP with LanceDB: guides/mcp.md
|
||||
- 🧬 Managing embeddings:
|
||||
- Understand Embeddings: embeddings/understanding_embeddings.md
|
||||
- Get Started: embeddings/index.md
|
||||
@@ -293,6 +294,7 @@ nav:
|
||||
- Choosing right query type: guides/tuning_retrievers/1_query_types.md
|
||||
- Reranking: guides/tuning_retrievers/2_reranking.md
|
||||
- Embedding fine-tuning: guides/tuning_retrievers/3_embed_tuning.md
|
||||
- Build MCP with LanceDB: guides/mcp.md
|
||||
- Managing Embeddings:
|
||||
- Understand Embeddings: embeddings/understanding_embeddings.md
|
||||
- Get Started: embeddings/index.md
|
||||
|
||||
126
docs/src/guides/mcp.md
Normal file
126
docs/src/guides/mcp.md
Normal file
@@ -0,0 +1,126 @@
|
||||
# MCP server with LanceDB
|
||||
|
||||
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.
|
||||
|
||||
With LanceDB, your MCP can be embedded in your application. Let's implement 2 simple MCP tools using LanceDB
|
||||
1. Add data - add data to LanceDB
|
||||
2. Retreive data - retrieve data from LanceDB
|
||||
|
||||
You need to install `mcp[cli]` python package.
|
||||
|
||||
First, let's define some configs:
|
||||
```python
|
||||
# mcp_server.py
|
||||
|
||||
LANCEDB_URI = "~/lancedb"
|
||||
TABLE_NAME = "mcp_data"
|
||||
EMBEDDING_FUNCTION = "sentence-transformers"
|
||||
MODEL_NAME = "all-MiniLM-L6-v2"
|
||||
```
|
||||
|
||||
Then initialize the table that we'll use to store and retreive data:
|
||||
```python
|
||||
import lancedb
|
||||
from lancedb.pydantic import LanceModel, Vector
|
||||
from lancedb.embeddings import get_registry
|
||||
|
||||
model = get_registry().get(EMBEDDING_FUNCTION).create(model_name=MODEL_NAME)
|
||||
|
||||
class Schema(LanceModel):
|
||||
text: str = model.SourceField()
|
||||
vector: Vector(model.ndims()) = model.VectorField()
|
||||
|
||||
db = lancedb.connect(LANCEDB_URI)
|
||||
if TABLE_NAME not in db.table_names():
|
||||
db.create_table(TABLE_NAME, schema=Schema)
|
||||
```
|
||||
|
||||
!!! Note "Using LanceDB cloud"
|
||||
If you want to use LanceDB cloud, you'll need to set the uri to your remote table
|
||||
instance and also provide a token. Every other functionality will remain the same
|
||||
|
||||
## Defining the tools
|
||||
Tools let LLMs take actions through your server. There are other components like `resources` that allow you to expose certain data sources to LLMs. For our use case, we need to define tools that LLMs can call in order to inget or retrieve data
|
||||
We'll use `FastMCP` interface of the MCP package. The FastMCP server is your core interface to the MCP protocol. It handles connection management, protocol compliance, and message routing.
|
||||
|
||||
```python
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
mcp = FastMCP("lancedb-example")
|
||||
```
|
||||
### Add data ingestion tool
|
||||
This function takes a string as input and adds it to the LanceDB table.
|
||||
|
||||
```python
|
||||
@mcp.tool()
|
||||
async def ingest_data(content: str) -> str:
|
||||
"""
|
||||
Add a new memory to the vector database
|
||||
Args:
|
||||
content: Content of the memory
|
||||
"""
|
||||
tbl = db[TABLE_NAME]
|
||||
tbl.add([
|
||||
{"text": content}
|
||||
])
|
||||
return f"Added memory: {content}"
|
||||
```
|
||||
### Retreive data tool
|
||||
|
||||
```python
|
||||
@mcp.tool()
|
||||
async def retrieve_data(query: str, limit: int = 5) -> str:
|
||||
"""
|
||||
Search db using vector search
|
||||
Args:
|
||||
query: The search query
|
||||
limit: Maximum number of results to return
|
||||
"""
|
||||
tbl = db[TABLE_NAME]
|
||||
rs = tbl.search(query).limit(limit).to_list()
|
||||
data = [
|
||||
r["text"] for r in rs
|
||||
]
|
||||
if not data:
|
||||
return "No relevant data found."
|
||||
|
||||
return "\n\n".join(data)
|
||||
```
|
||||
This function takes a string and limit as input and searches the LanceDB table for the most relevant memories.
|
||||
|
||||
|
||||
## Install it on Claude desktop
|
||||
|
||||
To install this MCP, you can simply run this command and it'll be registered on you Claude desktop
|
||||
```
|
||||
mcp install mcp_server.py
|
||||
```
|
||||
You'll see logs similar to this:
|
||||
```
|
||||
[04/07/25 20:18:08] INFO Load pretrained SentenceTransformer: BAAI/bge-small-en-v1.5 SentenceTransformer.py:218
|
||||
Batches: 100%|█████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 4.06it/s]
|
||||
[04/07/25 20:18:11] INFO Added server 'lancedb' to Claude config claude.py:129
|
||||
INFO Successfully installed lancedb in Claude app cli.py:467
|
||||
```
|
||||
|
||||
Now simply fire up claude desktop and you can start using it.
|
||||
|
||||
1. If installed correctly, you'll `lancedb` in the MCP apps list
|
||||

|
||||
|
||||
2. You can now use the `ingest_data` tool to add data to the table. To do that, you can simply ask claude using natural language
|
||||

|
||||
|
||||
3. Now you can start asking questions using the `retrieve_data` tool. It'll automatically search the table for relevant data. You should see something like this
|
||||

|
||||
|
||||
4. Claude tries to set the params for tool calling on its own but you can also specify the details.
|
||||

|
||||
|
||||
|
||||
## Community examples
|
||||
|
||||
- Find a minimal LanceDB mcp server similar to this [here](https://github.com/kyryl-opens-ml/mcp-server-lancedb/blob/main/src/mcp_lance_db/server.py)
|
||||
|
||||
- You can find an implementation of a more complex MCP server that uses LanceDB to implement an advanced CodeQA feature [here](https://github.com/lancedb/MCPExample).
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<parent>
|
||||
<groupId>com.lancedb</groupId>
|
||||
<artifactId>lancedb-parent</artifactId>
|
||||
<version>0.19.0-beta.4</version>
|
||||
<version>0.19.0-beta.5</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.lancedb</groupId>
|
||||
<artifactId>lancedb-parent</artifactId>
|
||||
<version>0.19.0-beta.4</version>
|
||||
<version>0.19.0-beta.5</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>LanceDB Parent</name>
|
||||
|
||||
49
node/package-lock.json
generated
49
node/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "vectordb",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "vectordb",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"cpu": [
|
||||
"x64",
|
||||
"arm64"
|
||||
@@ -52,11 +52,11 @@
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@lancedb/vectordb-darwin-arm64": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-darwin-x64": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-linux-arm64-gnu": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-linux-x64-gnu": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-win32-x64-msvc": "0.19.0-beta.4"
|
||||
"@lancedb/vectordb-darwin-arm64": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-darwin-x64": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-linux-arm64-gnu": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-linux-x64-gnu": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-win32-x64-msvc": "0.19.0-beta.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@apache-arrow/ts": "^14.0.2",
|
||||
@@ -327,60 +327,65 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@lancedb/vectordb-darwin-arm64": {
|
||||
"version": "0.19.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.19.0-beta.4.tgz",
|
||||
"integrity": "sha512-uS5AuT3Q4swrtM9JAhF8mM8Nt+kvewmB3DQWGiuYbhmMismSu8WlOHQAs9Yyh8N7NBdWENSTjroSExqjHPdFhQ==",
|
||||
"version": "0.19.0-beta.5",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-arm64/-/vectordb-darwin-arm64-0.19.0-beta.5.tgz",
|
||||
"integrity": "sha512-NuJVGaV4b6XgH3dlkCEquvtGM1cY5sIJE5M/LgJ3HYYvAbco/seBQM5AHTV/7CULoPEY9eQeJZOj9fWP5oQLYQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/@lancedb/vectordb-darwin-x64": {
|
||||
"version": "0.19.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-x64/-/vectordb-darwin-x64-0.19.0-beta.4.tgz",
|
||||
"integrity": "sha512-kjn3iTqZSx57ek9PN2AdPvJMx14tFkXc8sUFd3MLhY7FdWafx7Wvl0SLz2LubotJVFd6LMxvsPPNJEM5bEgMOw==",
|
||||
"version": "0.19.0-beta.5",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-darwin-x64/-/vectordb-darwin-x64-0.19.0-beta.5.tgz",
|
||||
"integrity": "sha512-hbadwvQcUgKJfluUHhN+mx+XeFRwTuh9mD0L3Tf3t3BkDTxyHpEG5WNgOpWrh6e1RU6zW54CoCyQuSEaVqGgGw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/@lancedb/vectordb-linux-arm64-gnu": {
|
||||
"version": "0.19.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-arm64-gnu/-/vectordb-linux-arm64-gnu-0.19.0-beta.4.tgz",
|
||||
"integrity": "sha512-iZlR7ffKC+XA1mGuuwXJojgFcUvXkgMt6pKR6lP3hsxXh8UOTWDljN7jkI8jKHcJez3rrqoqt1VjH3xD69fwtA==",
|
||||
"version": "0.19.0-beta.5",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-arm64-gnu/-/vectordb-linux-arm64-gnu-0.19.0-beta.5.tgz",
|
||||
"integrity": "sha512-fu/EOYLr3mx76/SP4dEgbq0vSYHfuTf68lVl5/tL6eIb1Purz42l22+jNKLJ/S3Plase2SkXdxyY90K2Y/CvSg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@lancedb/vectordb-linux-x64-gnu": {
|
||||
"version": "0.19.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.19.0-beta.4.tgz",
|
||||
"integrity": "sha512-uxLeerlT5FuWzuvHlTDLdLCakyUJ+qJitReoCKT6tKhfcjIkbr+NEoLZEHifJC4dRFPtbddVgiYN6VHlnPPD/w==",
|
||||
"version": "0.19.0-beta.5",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-linux-x64-gnu/-/vectordb-linux-x64-gnu-0.19.0-beta.5.tgz",
|
||||
"integrity": "sha512-pzb8fl5M8155sc/mEFnKmuh9rCfQohHBlb+j+5qNMe84AyygQ8Me1H3b1h9fOkUPu2Y168zYfuGkjNv4Bjm9eA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@lancedb/vectordb-win32-x64-msvc": {
|
||||
"version": "0.19.0-beta.4",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-win32-x64-msvc/-/vectordb-win32-x64-msvc-0.19.0-beta.4.tgz",
|
||||
"integrity": "sha512-QSugxudXooLCF7trudaAo9PfOzX7SFBIiHOoL4N6nwjC61u/JAsoiytw1Xjs/+0pOG5cT2WUMufBzBPgJyOxbw==",
|
||||
"version": "0.19.0-beta.5",
|
||||
"resolved": "https://registry.npmjs.org/@lancedb/vectordb-win32-x64-msvc/-/vectordb-win32-x64-msvc-0.19.0-beta.5.tgz",
|
||||
"integrity": "sha512-5z6BSfTuZYJdDL2wwRrEQlnfluahzaUH2U7vj3i4ik4zaAwvaYcrjmdYCTLRYhFscUqzxd2pVFHbfRYe+maYzA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vectordb",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"description": " Serverless, low-latency vector database for AI applications",
|
||||
"private": false,
|
||||
"main": "dist/index.js",
|
||||
@@ -89,10 +89,10 @@
|
||||
}
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@lancedb/vectordb-darwin-x64": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-darwin-arm64": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-linux-x64-gnu": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-linux-arm64-gnu": "0.19.0-beta.4",
|
||||
"@lancedb/vectordb-win32-x64-msvc": "0.19.0-beta.4"
|
||||
"@lancedb/vectordb-darwin-x64": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-darwin-arm64": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-linux-x64-gnu": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-linux-arm64-gnu": "0.19.0-beta.5",
|
||||
"@lancedb/vectordb-win32-x64-msvc": "0.19.0-beta.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "lancedb-nodejs"
|
||||
edition.workspace = true
|
||||
version = "0.19.0-beta.4"
|
||||
version = "0.19.0-beta.5"
|
||||
license.workspace = true
|
||||
description.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-darwin-arm64",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["arm64"],
|
||||
"main": "lancedb.darwin-arm64.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-darwin-x64",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["x64"],
|
||||
"main": "lancedb.darwin-x64.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-linux-arm64-gnu",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["linux"],
|
||||
"cpu": ["arm64"],
|
||||
"main": "lancedb.linux-arm64-gnu.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-linux-arm64-musl",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["linux"],
|
||||
"cpu": ["arm64"],
|
||||
"main": "lancedb.linux-arm64-musl.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-linux-x64-gnu",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["linux"],
|
||||
"cpu": ["x64"],
|
||||
"main": "lancedb.linux-x64-gnu.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-linux-x64-musl",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["linux"],
|
||||
"cpu": ["x64"],
|
||||
"main": "lancedb.linux-x64-musl.node",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-win32-arm64-msvc",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb-win32-x64-msvc",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"os": ["win32"],
|
||||
"cpu": ["x64"],
|
||||
"main": "lancedb.win32-x64-msvc.node",
|
||||
|
||||
4
nodejs/package-lock.json
generated
4
nodejs/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@lancedb/lancedb",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lancedb/lancedb",
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"cpu": [
|
||||
"x64",
|
||||
"arm64"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"ann"
|
||||
],
|
||||
"private": false,
|
||||
"version": "0.19.0-beta.4",
|
||||
"version": "0.19.0-beta.5",
|
||||
"main": "dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "lancedb-node"
|
||||
version = "0.19.0-beta.4"
|
||||
version = "0.19.0-beta.5"
|
||||
description = "Serverless, low-latency vector database for AI applications"
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "lancedb"
|
||||
version = "0.19.0-beta.4"
|
||||
version = "0.19.0-beta.5"
|
||||
edition.workspace = true
|
||||
description = "LanceDB: A serverless, low-latency vector database for AI applications"
|
||||
license.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user