Skip to content

Commit 28a0fe5

Browse files
hardikjshahHardik Shah
andauthored
fix: Update rag examples to use fresh faiss index every time (llamastack#998)
# What does this PR do? In several examples we use the same faiss index , which means running it multiple times fills up the index with duplicates which eventually degrades the model performance on RAG as multiple copies of the same irrelevant chunks might be picked up several times. Fix is to ensure we create a new index each time. Resolves issue in this discussion - llamastack#995 ## Test Plan Re-ran the getting started guide multiple times to see the same output Co-authored-by: Hardik Shah <hjshah@fb.com>
1 parent 06e5af1 commit 28a0fe5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

docs/getting_started.ipynb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"# install a branch of llama stack\n",
9090
"import os\n",
9191
"os.environ[\"UV_SYSTEM_PYTHON\"] = \"1\"\n",
92-
"!pip install uv \n",
92+
"!pip install uv\n",
9393
"!uv pip install llama-stack"
9494
]
9595
},
@@ -691,7 +691,7 @@
691691
" from google.colab import userdata\n",
692692
" os.environ['TOGETHER_API_KEY'] = userdata.get('TOGETHER_API_KEY')\n",
693693
" os.environ['TAVILY_SEARCH_API_KEY'] = userdata.get('TAVILY_SEARCH_API_KEY')\n",
694-
"except ImportError: \n",
694+
"except ImportError:\n",
695695
" print(\"Not in Google Colab environment\")\n",
696696
"\n",
697697
"for key in ['TOGETHER_API_KEY', 'TAVILY_SEARCH_API_KEY']:\n",
@@ -1656,6 +1656,7 @@
16561656
}
16571657
],
16581658
"source": [
1659+
"import uuid\n",
16591660
"from llama_stack_client.lib.agents.agent import Agent\n",
16601661
"from llama_stack_client.lib.agents.event_logger import EventLogger\n",
16611662
"from llama_stack_client.types.agent_create_params import AgentConfig\n",
@@ -1673,7 +1674,7 @@
16731674
" for i, url in enumerate(urls)\n",
16741675
"]\n",
16751676
"\n",
1676-
"vector_db_id = \"test-vector-db\"\n",
1677+
"vector_db_id = f\"test-vector-db-{uuid.uuid4().hex}\"\n",
16771678
"client.vector_dbs.register(\n",
16781679
" vector_db_id=vector_db_id,\n",
16791680
" embedding_model=\"all-MiniLM-L6-v2\",\n",
@@ -3098,7 +3099,7 @@
30983099
}
30993100
],
31003101
"source": [
3101-
"# NBVAL_SKIP \n",
3102+
"# NBVAL_SKIP\n",
31023103
"print(f\"Getting traces for session_id={session_id}\")\n",
31033104
"import json\n",
31043105
"\n",

docs/source/getting_started/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ Here is an example of a simple RAG (Retrieval Augmented Generation) chatbot agen
173173
174174
```python
175175
import os
176+
import uuid
176177
from termcolor import cprint
177178

178179
from llama_stack_client.lib.agents.agent import Agent
@@ -214,7 +215,7 @@ documents = [
214215
]
215216

216217
# Register a vector database
217-
vector_db_id = "test-vector-db"
218+
vector_db_id = f"test-vector-db-{uuid.uuid4().hex}"
218219
client.vector_dbs.register(
219220
vector_db_id=vector_db_id,
220221
embedding_model="all-MiniLM-L6-v2",

tests/client-sdk/agents/test_agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def test_override_system_message_behavior(llama_stack_client, agent_config):
297297
You are an expert in composing functions. You are given a question and a set of possible functions.
298298
Based on the question, you may or may not need to make one or more function/tool calls to achieve the purpose.
299299
If none of the function can be used, don't return [], instead answer the question directly without using functions. If the given question lacks the parameters required by the function,
300-
also point it out.
300+
also point it out.
301301
302302
{{ function_description }}
303303
"""
@@ -414,7 +414,7 @@ def test_rag_and_code_agent(llama_stack_client, agent_config):
414414
)
415415
for i, url in enumerate(urls)
416416
]
417-
vector_db_id = "test-vector-db"
417+
vector_db_id = f"test-vector-db-{uuid4()}"
418418
llama_stack_client.vector_dbs.register(
419419
vector_db_id=vector_db_id,
420420
embedding_model="all-MiniLM-L6-v2",

0 commit comments

Comments
 (0)