docs: improve rag example code in doc

Signed-off-by: reidliu <reid201711@gmail.com>
This commit is contained in:
reidliu 2025-03-05 21:41:59 +08:00
parent 3fabe076cd
commit b5321924a5

View file

@ -20,6 +20,11 @@ We may add more storage types like Graph IO in the future.
Here's how to set up a vector database for RAG: Here's how to set up a vector database for RAG:
```python ```python
# Create http client
from llama_stack_client import LlamaStackClient
client = LlamaStackClient(base_url=f"http://localhost:{os.environ['LLAMA_STACK_PORT']}")
# Register a vector db # Register a vector db
vector_db_id = "my_documents" vector_db_id = "my_documents"
response = client.vector_dbs.register( response = client.vector_dbs.register(
@ -136,6 +141,14 @@ response = agent.create_turn(
) )
``` ```
You can print the response with below.
```python
from llama_stack_client.lib.agents.event_logger import EventLogger
for log in EventLogger().log(response):
log.print()
```
### Unregistering Vector DBs ### Unregistering Vector DBs
If you need to clean up and unregister vector databases, you can do so as follows: If you need to clean up and unregister vector databases, you can do so as follows: