Skip to content

Commit 024ab72

Browse files
Pull vector.db from oci registry
1 parent 8406e41 commit 024ab72

File tree

4 files changed

+450
-0
lines changed

4 files changed

+450
-0
lines changed

examples/embeddings/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Embeddings OCI Examples
2+
3+
This directory contains examples for pulling and pushing vector database embeddings to/from OCI registries.
4+
5+
## Pull Example
6+
7+
Downloads the embeddings OCI artifact and installs the vector.db directory to `~/.docker/mcp/`.
8+
9+
### Usage
10+
11+
```bash
12+
# From repository root
13+
go run ./examples/embeddings/pull.go
14+
```
15+
16+
The Pull function will:
17+
1. Download the image from `jimclark106/embeddings:latest`
18+
2. Extract all layers to a temporary directory
19+
3. Verify that `vectors.db` file exists
20+
4. Copy `vectors.db` to `~/.docker/mcp/` (skips if already exists)
21+
5. Clean up temporary files
22+
23+
## Push Example
24+
25+
Creates an OCI artifact from a local vector.db directory and pushes it to a registry.
26+
27+
### Usage
28+
29+
```bash
30+
# From repository root
31+
go run ./examples/embeddings/push.go <vector-db-path> <oci-ref>
32+
```
33+
34+
### Example
35+
36+
```bash
37+
# Push the local vectors.db to your own registry
38+
go run ./examples/embeddings/push.go ~/.docker/mcp/vectors.db jimclark106/embeddings:v1.0
39+
```
40+
41+
The Push function will:
42+
1. Verify the source directory exists
43+
2. Create a tar archive from the entire directory tree (always naming the root as `vectors.db` in the archive)
44+
3. Create an OCI image layer from the tar
45+
4. Push the image to the specified OCI reference
46+
47+
Note: Regardless of your local directory name, the OCI artifact will always contain `vectors.db` at the root for consistency.
48+
49+
## Authentication
50+
51+
Both examples use the Docker credential helper for authentication. Make sure you're logged in to the registry:
52+
53+
```bash
54+
docker login
55+
```
56+
57+
## Notes
58+
59+
- Pull is idempotent - it won't overwrite existing `vectors.db` files
60+
- Push requires write access to the specified OCI registry
61+
- Push always stores the directory as `vectors.db` in the OCI artifact for consistency
62+
- File permissions and symlinks are preserved during push/pull operations

examples/embeddings/pull.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/docker/mcp-gateway/pkg/gateway/embeddings"
9+
)
10+
11+
func main() {
12+
fmt.Println("Pulling embeddings from OCI registry...")
13+
14+
if err := embeddings.Pull(context.Background()); err != nil {
15+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
16+
os.Exit(1)
17+
}
18+
19+
fmt.Println("Successfully pulled embeddings!")
20+
}

examples/embeddings/push.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/docker/mcp-gateway/pkg/gateway/embeddings"
9+
)
10+
11+
func main() {
12+
if len(os.Args) != 3 {
13+
fmt.Fprintf(os.Stderr, "Usage: %s <vector-db-path> <oci-ref>\n", os.Args[0])
14+
fmt.Fprintf(os.Stderr, "\nExample:\n")
15+
fmt.Fprintf(os.Stderr, " %s ~/.docker/mcp/vectors.db jimclark106/embeddings:v1.0\n", os.Args[0])
16+
fmt.Fprintf(os.Stderr, "\nNote: The directory will be stored as 'vectors.db' in the OCI artifact.\n")
17+
os.Exit(1)
18+
}
19+
20+
vectorDBPath := os.Args[1]
21+
ociRef := os.Args[2]
22+
23+
fmt.Printf("Pushing vector database from %s to %s...\n", vectorDBPath, ociRef)
24+
25+
if err := embeddings.Push(context.Background(), vectorDBPath, ociRef); err != nil {
26+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
27+
os.Exit(1)
28+
}
29+
30+
fmt.Printf("Successfully pushed to %s!\n", ociRef)
31+
}

0 commit comments

Comments
 (0)