Skip to content

Commit 9f077e8

Browse files
committed
Variable RAG DB setup for query, query v2, and streaming query
Signed-off-by: Lucas <lyoon@redhat.com>
1 parent 6bae4a2 commit 9f077e8

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
@@ -728,9 +728,14 @@ async def retrieve_response( # pylint: disable=too-many-locals,too-many-branche
728728
),
729729
}
730730

731-
vector_db_ids = [
732-
vector_store.id for vector_store in (await client.vector_stores.list()).data
733-
]
731+
# Use specified vector stores or fetch all available ones
732+
if query_request.vector_store_ids:
733+
vector_db_ids = query_request.vector_store_ids
734+
else:
735+
vector_db_ids = [
736+
vector_store.id
737+
for vector_store in (await client.vector_stores.list()).data
738+
]
734739
toolgroups = (get_rag_toolgroups(vector_db_ids) or []) + [
735740
mcp_server.name for mcp_server in configuration.mcp_servers
736741
]

src/app/endpoints/query_v2.py

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

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

751754
# Add RAG tools if vector stores are available
752755
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)