Skip to content

Commit 35462ef

Browse files
authored
Update lib cli (#96)
# What does this PR do? Moves memory bank subcommand to vector db Updates the reference Test plan ![Screenshot 2025-01-23 at 3 24 40 PM](https://github.com/user-attachments/assets/a565c92e-2b74-487f-b3ed-982ef54721e5)
1 parent 2762b70 commit 35462ef

File tree

5 files changed

+175
-165
lines changed

5 files changed

+175
-165
lines changed

docs/cli_reference.md

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,33 @@ $ llama-stack-client models update <model_id> [--provider-id <provider_id>] [--p
100100
$ llama-stack-client models delete <model_id>
101101
```
102102

103-
#### `llama-stack-client memory_banks list`
103+
#### `llama-stack-client vector_dbs list`
104104
```bash
105-
$ llama-stack-client memory_banks list
105+
$ llama-stack-client vector_dbs list
106106
```
107107
```
108-
+--------------+----------------+--------+-------------------+------------------------+--------------------------+
109-
| identifier | provider_id | type | embedding_model | chunk_size_in_tokens | overlap_size_in_tokens |
110-
+==============+================+========+===================+========================+==========================+
111-
| test_bank | meta-reference | vector | all-MiniLM-L6-v2 | 512 | 64 |
112-
+--------------+----------------+--------+-------------------+------------------------+--------------------------+
108+
+--------------+----------------+---------------------+---------------+------------------------+
109+
| identifier | provider_id | provider_resource_id| vector_db_type| params |
110+
+==============+================+=====================+===============+========================+
111+
| test_bank | meta-reference | test_bank | vector | embedding_model: all-MiniLM-L6-v2
112+
embedding_dimension: 384|
113+
+--------------+----------------+---------------------+---------------+------------------------+
113114
```
114115

115-
#### `llama-stack-client memory_banks register`
116+
#### `llama-stack-client vector_dbs register`
116117
```bash
117-
$ llama-stack-client memory_banks register <memory-bank-id> --type <type> [--provider-id <provider-id>] [--provider-memory-bank-id <provider-memory-bank-id>] [--chunk-size <chunk-size>] [--embedding-model <embedding-model>] [--overlap-size <overlap-size>]
118+
$ llama-stack-client vector_dbs register <vector-db-id> [--provider-id <provider-id>] [--provider-vector-db-id <provider-vector-db-id>] [--embedding-model <embedding-model>] [--embedding-dimension <embedding-dimension>]
118119
```
119120

120121
Options:
121-
- `--type`: Required. Type of memory bank. Choices: "vector", "keyvalue", "keyword", "graph"
122-
- `--provider-id`: Optional. Provider ID for the memory bank
123-
- `--provider-memory-bank-id`: Optional. Provider's memory bank ID
124-
- `--chunk-size`: Optional. Chunk size in tokens (for vector type). Default: 512
125-
- `--embedding-model`: Optional. Embedding model (for vector type). Default: "all-MiniLM-L6-v2"
126-
- `--overlap-size`: Optional. Overlap size in tokens (for vector type). Default: 64
122+
- `--provider-id`: Optional. Provider ID for the vector db
123+
- `--provider-vector-db-id`: Optional. Provider's vector db ID
124+
- `--embedding-model`: Optional. Embedding model to use. Default: "all-MiniLM-L6-v2"
125+
- `--embedding-dimension`: Optional. Dimension of embeddings. Default: 384
127126

128-
#### `llama-stack-client memory_banks unregister`
127+
#### `llama-stack-client vector_dbs unregister`
129128
```bash
130-
$ llama-stack-client memory_banks unregister <memory-bank-id>
129+
$ llama-stack-client vector_dbs unregister <vector-db-id>
131130
```
132131

133132
#### `llama-stack-client shields list`
@@ -212,3 +211,42 @@ Options:
212211
- `--output-dir`: Required. Path to the directory where scoring results will be saved
213212
- `--num-examples`: Optional. Number of examples to evaluate (useful for debugging)
214213
- `--visualize`: Optional flag. If set, visualizes scoring results after completion
214+
215+
#### `llama-stack-client toolgroups list`
216+
```bash
217+
$ llama-stack-client toolgroups list
218+
```
219+
```
220+
+---------------------------+------------------+------+---------------+
221+
| identifier | provider_id | args | mcp_endpoint |
222+
+===========================+==================+======+===============+
223+
| builtin::code_interpreter | code-interpreter | None | None |
224+
+---------------------------+------------------+------+---------------+
225+
| builtin::rag | rag-runtime | None | None |
226+
+---------------------------+------------------+------+---------------+
227+
| builtin::websearch | tavily-search | None | None |
228+
+---------------------------+------------------+------+---------------+
229+
```
230+
231+
#### `llama-stack-client toolgroups get`
232+
```bash
233+
$ llama-stack-client toolgroups get <toolgroup_id>
234+
```
235+
236+
Shows detailed information about a specific toolgroup. If the toolgroup is not found, displays an error message.
237+
238+
#### `llama-stack-client toolgroups register`
239+
```bash
240+
$ llama-stack-client toolgroups register <toolgroup_id> [--provider-id <provider-id>] [--provider-toolgroup-id <provider-toolgroup-id>] [--mcp-config <mcp-config>] [--args <args>]
241+
```
242+
243+
Options:
244+
- `--provider-id`: Optional. Provider ID for the toolgroup
245+
- `--provider-toolgroup-id`: Optional. Provider's toolgroup ID
246+
- `--mcp-config`: Optional. JSON configuration for the MCP endpoint
247+
- `--args`: Optional. JSON arguments for the toolgroup
248+
249+
#### `llama-stack-client toolgroups unregister`
250+
```bash
251+
$ llama-stack-client toolgroups unregister <toolgroup_id>
252+
```

src/llama_stack_client/lib/cli/llama_stack_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
from .eval_tasks import eval_tasks
2020
from .inference import inference
2121
from .inspect import inspect
22-
from .memory_banks import memory_banks
2322
from .models import models
2423
from .post_training import post_training
2524
from .providers import providers
2625
from .scoring_functions import scoring_functions
2726
from .shields import shields
2827
from .toolgroups import toolgroups
28+
from .vector_dbs import vector_dbs
2929

3030

3131
@click.group()
@@ -60,7 +60,7 @@ def cli(ctx, endpoint: str, config: str | None):
6060
click.echo("Falling back to HTTP client with endpoint", err=True)
6161

6262
if endpoint == "":
63-
endpoint = "http://localhost:5000"
63+
endpoint = "http://localhost:8321"
6464

6565
client = LlamaStackClient(
6666
base_url=endpoint,
@@ -75,7 +75,7 @@ def cli(ctx, endpoint: str, config: str | None):
7575

7676
# Register all subcommands
7777
cli.add_command(models, "models")
78-
cli.add_command(memory_banks, "memory_banks")
78+
cli.add_command(vector_dbs, "vector_dbs")
7979
cli.add_command(shields, "shields")
8080
cli.add_command(eval_tasks, "eval_tasks")
8181
cli.add_command(providers, "providers")

src/llama_stack_client/lib/cli/memory_banks/memory_banks.py

Lines changed: 0 additions & 143 deletions
This file was deleted.

src/llama_stack_client/lib/cli/memory_banks/__init__.py renamed to src/llama_stack_client/lib/cli/vector_dbs/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
# This source code is licensed under the terms described in the LICENSE file in
55
# the root directory of this source tree.
66

7-
from .memory_banks import memory_banks
7+
from .vector_dbs import vector_dbs
88

9-
__all__ = ["memory_banks"]
9+
__all__ = ["vector_dbs"]
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the terms described in the LICENSE file in
5+
# the root directory of this source tree.
6+
7+
from typing import Optional
8+
9+
import click
10+
import yaml
11+
from rich.console import Console
12+
from rich.table import Table
13+
14+
from ..common.utils import handle_client_errors
15+
16+
17+
@click.group()
18+
def vector_dbs():
19+
"""Query details about available vector dbs on distribution."""
20+
pass
21+
22+
23+
@click.command("list")
24+
@click.pass_context
25+
@handle_client_errors("list vector dbs")
26+
def list(ctx):
27+
"""Show available vector dbs on distribution endpoint"""
28+
29+
client = ctx.obj["client"]
30+
console = Console()
31+
vector_dbs_list_response = client.vector_dbs.list()
32+
33+
if vector_dbs_list_response:
34+
table = Table()
35+
# Add our specific columns
36+
table.add_column("identifier")
37+
table.add_column("provider_id")
38+
table.add_column("provider_resource_id")
39+
table.add_column("vector_db_type")
40+
table.add_column("params")
41+
42+
for item in vector_dbs_list_response:
43+
# Create a dict of all attributes
44+
item_dict = item.__dict__
45+
46+
# Extract our main columns
47+
identifier = str(item_dict.pop("identifier", ""))
48+
provider_id = str(item_dict.pop("provider_id", ""))
49+
provider_resource_id = str(item_dict.pop("provider_resource_id", ""))
50+
vector_db_type = str(item_dict.pop("vector_db_type", ""))
51+
# Convert remaining attributes to YAML string for params column
52+
params = yaml.dump(item_dict, default_flow_style=False)
53+
54+
table.add_row(
55+
identifier, provider_id, provider_resource_id, vector_db_type, params
56+
)
57+
58+
console.print(table)
59+
60+
61+
@vector_dbs.command()
62+
@click.argument("vector-db-id")
63+
@click.option("--provider-id", help="Provider ID for the vector db", default=None)
64+
@click.option("--provider-vector-db-id", help="Provider's vector db ID", default=None)
65+
@click.option(
66+
"--embedding-model",
67+
type=str,
68+
help="Embedding model (for vector type)",
69+
default="all-MiniLM-L6-v2",
70+
)
71+
@click.option(
72+
"--embedding-dimension",
73+
type=int,
74+
help="Embedding dimension (for vector type)",
75+
default=384,
76+
)
77+
@click.pass_context
78+
@handle_client_errors("register vector db")
79+
def register(
80+
ctx,
81+
vector_db_id: str,
82+
provider_id: Optional[str],
83+
provider_vector_db_id: Optional[str],
84+
embedding_model: Optional[str],
85+
embedding_dimension: Optional[int],
86+
):
87+
"""Create a new vector db"""
88+
client = ctx.obj["client"]
89+
90+
response = client.vector_dbs.register(
91+
vector_db_id=vector_db_id,
92+
provider_id=provider_id,
93+
provider_vector_db_id=provider_vector_db_id,
94+
embedding_model=embedding_model,
95+
embedding_dimension=embedding_dimension,
96+
)
97+
if response:
98+
click.echo(yaml.dump(response.dict()))
99+
100+
101+
@vector_dbs.command()
102+
@click.argument("vector-db-id")
103+
@click.pass_context
104+
@handle_client_errors("delete vector db")
105+
def unregister(ctx, vector_db_id: str):
106+
"""Delete a vector db"""
107+
client = ctx.obj["client"]
108+
client.vector_dbs.unregister(vector_db_id=vector_db_id)
109+
click.echo(f"Vector db '{vector_db_id}' deleted successfully")
110+
111+
112+
# Register subcommands
113+
vector_dbs.add_command(list)
114+
vector_dbs.add_command(register)
115+
vector_dbs.add_command(unregister)

0 commit comments

Comments
 (0)