Skip to content

Commit 586b91e

Browse files
authored
Merge pull request lightspeed-core#908 from JslYoon/JslYoon-RAG_toggle
Variable RAG DB setup for query, query v2, and streaming query
2 parents 383b1a8 + 9f077e8 commit 586b91e

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/app/endpoints/query.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,14 @@ async def retrieve_response( # pylint: disable=too-many-locals,too-many-branche
751751
),
752752
}
753753

754-
vector_db_ids = [
755-
vector_store.id for vector_store in (await client.vector_stores.list()).data
756-
]
754+
# Use specified vector stores or fetch all available ones
755+
if query_request.vector_store_ids:
756+
vector_db_ids = query_request.vector_store_ids
757+
else:
758+
vector_db_ids = [
759+
vector_store.id
760+
for vector_store in (await client.vector_stores.list()).data
761+
]
757762
toolgroups = (get_rag_toolgroups(vector_db_ids) or []) + [
758763
mcp_server.name for mcp_server in configuration.mcp_servers
759764
]

src/app/endpoints/query_v2.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,13 @@ async def prepare_tools_for_responses_api(
741741
return None
742742

743743
toolgroups = []
744-
# Get vector stores for RAG tools
745-
vector_store_ids = [
746-
vector_store.id for vector_store in (await client.vector_stores.list()).data
747-
]
744+
# Get vector stores for RAG tools - use specified ones or fetch all
745+
if query_request.vector_store_ids:
746+
vector_store_ids = query_request.vector_store_ids
747+
else:
748+
vector_store_ids = [
749+
vector_store.id for vector_store in (await client.vector_stores.list()).data
750+
]
748751

749752
# Add RAG tools if vector stores are available
750753
rag_tools = get_rag_tools(vector_store_ids)

src/app/endpoints/streaming_query.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,14 @@ async def retrieve_response(
10881088
),
10891089
}
10901090

1091-
vector_db_ids = [
1092-
vector_store.id for vector_store in (await client.vector_stores.list()).data
1093-
]
1091+
# Use specified vector stores or fetch all available ones
1092+
if query_request.vector_store_ids:
1093+
vector_db_ids = query_request.vector_store_ids
1094+
else:
1095+
vector_db_ids = [
1096+
vector_store.id
1097+
for vector_store in (await client.vector_stores.list()).data
1098+
]
10941099
toolgroups = (get_rag_toolgroups(vector_db_ids) or []) + [
10951100
mcp_server.name for mcp_server in configuration.mcp_servers
10961101
]

src/models/requests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class QueryRequest(BaseModel):
8383
no_tools: Whether to bypass all tools and MCP servers (default: False).
8484
generate_topic_summary: Whether to generate topic summary for new conversations.
8585
media_type: The optional media type for response format (application/json or text/plain).
86+
vector_store_ids: The optional list of specific vector store IDs to query for RAG.
8687
8788
Example:
8889
```python
@@ -159,6 +160,13 @@ class QueryRequest(BaseModel):
159160
examples=[MEDIA_TYPE_JSON, MEDIA_TYPE_TEXT],
160161
)
161162

163+
vector_store_ids: Optional[list[str]] = Field(
164+
None,
165+
description="Optional list of specific vector store IDs to query for RAG. "
166+
"If not provided, all available vector stores will be queried.",
167+
examples=["ocp_docs", "knowledge_base", "vector_db_1"],
168+
)
169+
162170
# provides examples for /docs endpoint
163171
model_config = {
164172
"extra": "forbid",
@@ -172,6 +180,7 @@ class QueryRequest(BaseModel):
172180
"system_prompt": "You are a helpful assistant",
173181
"no_tools": False,
174182
"generate_topic_summary": True,
183+
"vector_store_ids": ["ocp_docs", "knowledge_base"],
175184
"attachments": [
176185
{
177186
"attachment_type": "log",

0 commit comments

Comments
 (0)