Skip to content

Commit b6ccb45

Browse files
committed
Move query and streaming_query to vector_stores
1 parent 0a130b0 commit b6ccb45

4 files changed

Lines changed: 117 additions & 63 deletions

File tree

src/app/endpoints/query.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,10 @@ async def retrieve_response( # pylint: disable=too-many-locals,too-many-branche
733733
),
734734
}
735735

736-
vector_db_ids = [
737-
vector_db.identifier for vector_db in await client.vector_dbs.list()
736+
vector_store_ids = [
737+
vector_store.id for vector_store in (await client.vector_stores.list()).data
738738
]
739-
toolgroups = (get_rag_toolgroups(vector_db_ids) or []) + [
739+
toolgroups = (get_rag_toolgroups(vector_store_ids) or []) + [
740740
mcp_server.name for mcp_server in configuration.mcp_servers
741741
]
742742
# Convert empty list to None for consistency with existing behavior
@@ -830,30 +830,30 @@ def validate_attachments_metadata(attachments: list[Attachment]) -> None:
830830

831831

832832
def get_rag_toolgroups(
833-
vector_db_ids: list[str],
833+
vector_store_ids: list[str],
834834
) -> list[Toolgroup] | None:
835835
"""
836-
Return a list of RAG Tool groups if the given vector DB list is not empty.
836+
Return a list of RAG Tool groups if the given vector store list is not empty.
837837
838838
Generate a list containing a RAG knowledge search toolgroup if
839-
vector database IDs are provided.
839+
vector store IDs are provided.
840840
841841
Parameters:
842-
vector_db_ids (list[str]): List of vector database identifiers to include in the toolgroup.
842+
vector_store_ids (list[str]): List of vector store identifiers to include in the toolgroup.
843843
844844
Returns:
845845
list[Toolgroup] | None: A list with a single RAG toolgroup if
846-
vector_db_ids is non-empty; otherwise, None.
846+
vector_store_ids is non-empty; otherwise, None.
847847
"""
848848
return (
849849
[
850850
ToolgroupAgentToolGroupWithArgs(
851851
name="builtin::rag/knowledge_search",
852852
args={
853-
"vector_db_ids": vector_db_ids,
853+
"vector_db_ids": vector_store_ids,
854854
},
855855
)
856856
]
857-
if vector_db_ids
857+
if vector_store_ids
858858
else None
859859
)

src/app/endpoints/streaming_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,10 @@ async def retrieve_response(
10611061
),
10621062
}
10631063

1064-
vector_db_ids = [
1065-
vector_db.identifier for vector_db in await client.vector_dbs.list()
1064+
vector_store_ids = [
1065+
vector_store.id for vector_store in (await client.vector_stores.list()).data
10661066
]
1067-
toolgroups = (get_rag_toolgroups(vector_db_ids) or []) + [
1067+
toolgroups = (get_rag_toolgroups(vector_store_ids) or []) + [
10681068
mcp_server.name for mcp_server in configuration.mcp_servers
10691069
]
10701070
# Convert empty list to None for consistency with existing behavior

tests/unit/app/endpoints/test_query.py

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,11 @@ async def test_retrieve_response_no_returned_message(
536536
mock_client, mock_agent = prepare_agent_mocks
537537
mock_agent.create_turn.return_value.output_message = None
538538
mock_client.shields.list.return_value = []
539-
mock_vector_db = mocker.Mock()
540-
mock_vector_db.identifier = "VectorDB-1"
541-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
539+
mock_vector_store = mocker.Mock()
540+
mock_vector_store.id = "VectorDB-1"
541+
mock_vector_stores_response = mocker.Mock()
542+
mock_vector_stores_response.data = [mock_vector_store]
543+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
542544

543545
# Mock configuration with empty MCP servers
544546
mock_config = mocker.Mock()
@@ -574,9 +576,11 @@ async def test_retrieve_response_message_without_content(
574576
mock_client, mock_agent = prepare_agent_mocks
575577
mock_agent.create_turn.return_value.output_message.content = None
576578
mock_client.shields.list.return_value = []
577-
mock_vector_db = mocker.Mock()
578-
mock_vector_db.identifier = "VectorDB-1"
579-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
579+
mock_vector_store = mocker.Mock()
580+
mock_vector_store.id = "VectorDB-1"
581+
mock_vector_stores_response = mocker.Mock()
582+
mock_vector_stores_response.data = [mock_vector_store]
583+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
580584

581585
# Mock configuration with empty MCP servers
582586
mock_config = mocker.Mock()
@@ -613,9 +617,11 @@ async def test_retrieve_response_vector_db_available(
613617
mock_client, mock_agent = prepare_agent_mocks
614618
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
615619
mock_client.shields.list.return_value = []
616-
mock_vector_db = mocker.Mock()
617-
mock_vector_db.identifier = "VectorDB-1"
618-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
620+
mock_vector_store = mocker.Mock()
621+
mock_vector_store.id = "VectorDB-1"
622+
mock_vector_stores_response = mocker.Mock()
623+
mock_vector_stores_response.data = [mock_vector_store]
624+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
619625

620626
# Mock configuration with empty MCP servers
621627
mock_config = mocker.Mock()
@@ -660,7 +666,9 @@ async def test_retrieve_response_no_available_shields(
660666
mock_client, mock_agent = prepare_agent_mocks
661667
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
662668
mock_client.shields.list.return_value = []
663-
mock_client.vector_dbs.list.return_value = []
669+
mock_vector_stores_response = mocker.Mock()
670+
mock_vector_stores_response.data = []
671+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
664672

665673
# Mock configuration with empty MCP servers
666674
mock_config = mocker.Mock()
@@ -716,7 +724,9 @@ def __repr__(self) -> str:
716724
mock_client, mock_agent = prepare_agent_mocks
717725
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
718726
mock_client.shields.list.return_value = [MockShield("shield1")]
719-
mock_client.vector_dbs.list.return_value = []
727+
mock_vector_stores_response = mocker.Mock()
728+
mock_vector_stores_response.data = []
729+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
720730

721731
# Mock configuration with empty MCP servers
722732
mock_config = mocker.Mock()
@@ -775,7 +785,9 @@ def __repr__(self) -> str:
775785
MockShield("shield1"),
776786
MockShield("shield2"),
777787
]
778-
mock_client.vector_dbs.list.return_value = []
788+
mock_vector_stores_response = mocker.Mock()
789+
mock_vector_stores_response.data = []
790+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
779791

780792
# Mock configuration with empty MCP servers
781793
mock_config = mocker.Mock()
@@ -836,7 +848,9 @@ def __repr__(self) -> str:
836848
MockShield("output_shield3"),
837849
MockShield("inout_shield4"),
838850
]
839-
mock_client.vector_dbs.list.return_value = []
851+
mock_vector_stores_response = mocker.Mock()
852+
mock_vector_stores_response.data = []
853+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
840854

841855
# Mock configuration with empty MCP servers
842856
mock_config = mocker.Mock()
@@ -891,7 +905,9 @@ async def test_retrieve_response_with_one_attachment(
891905
mock_client, mock_agent = prepare_agent_mocks
892906
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
893907
mock_client.shields.list.return_value = []
894-
mock_client.vector_dbs.list.return_value = []
908+
mock_vector_stores_response = mocker.Mock()
909+
mock_vector_stores_response.data = []
910+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
895911

896912
# Mock configuration with empty MCP servers
897913
mock_config = mocker.Mock()
@@ -947,7 +963,9 @@ async def test_retrieve_response_with_two_attachments(
947963
mock_client, mock_agent = prepare_agent_mocks
948964
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
949965
mock_client.shields.list.return_value = []
950-
mock_client.vector_dbs.list.return_value = []
966+
mock_vector_stores_response = mocker.Mock()
967+
mock_vector_stores_response.data = []
968+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
951969

952970
# Mock configuration with empty MCP servers
953971
mock_config = mocker.Mock()
@@ -1129,7 +1147,9 @@ async def test_retrieve_response_with_mcp_servers(
11291147
mock_client, mock_agent = prepare_agent_mocks
11301148
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
11311149
mock_client.shields.list.return_value = []
1132-
mock_client.vector_dbs.list.return_value = []
1150+
mock_vector_stores_response = mocker.Mock()
1151+
mock_vector_stores_response.data = []
1152+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
11331153

11341154
# Mock configuration with MCP servers
11351155
mcp_servers = [
@@ -1210,7 +1230,9 @@ async def test_retrieve_response_with_mcp_servers_empty_token(
12101230
mock_client, mock_agent = prepare_agent_mocks
12111231
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
12121232
mock_client.shields.list.return_value = []
1213-
mock_client.vector_dbs.list.return_value = []
1233+
mock_vector_stores_response = mocker.Mock()
1234+
mock_vector_stores_response.data = []
1235+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
12141236

12151237
# Mock configuration with MCP servers
12161238
mcp_servers = [
@@ -1269,7 +1291,9 @@ async def test_retrieve_response_with_mcp_servers_and_mcp_headers(
12691291
mock_client, mock_agent = prepare_agent_mocks
12701292
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
12711293
mock_client.shields.list.return_value = []
1272-
mock_client.vector_dbs.list.return_value = []
1294+
mock_vector_stores_response = mocker.Mock()
1295+
mock_vector_stores_response.data = []
1296+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
12731297

12741298
# Mock configuration with MCP servers
12751299
mcp_servers = [
@@ -1380,9 +1404,11 @@ async def test_retrieve_response_shield_violation(
13801404
text="LLM answer", type="text"
13811405
)
13821406
mock_client.shields.list.return_value = []
1383-
mock_vector_db = mocker.Mock()
1384-
mock_vector_db.identifier = "VectorDB-1"
1385-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
1407+
mock_vector_store = mocker.Mock()
1408+
mock_vector_store.id = "VectorDB-1"
1409+
mock_vector_stores_response = mocker.Mock()
1410+
mock_vector_stores_response.data = [mock_vector_store]
1411+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
13861412

13871413
# Mock configuration with empty MCP servers
13881414
mock_config = mocker.Mock()
@@ -1419,16 +1445,16 @@ async def test_retrieve_response_shield_violation(
14191445

14201446
def test_get_rag_toolgroups() -> None:
14211447
"""Test get_rag_toolgroups function."""
1422-
vector_db_ids: list[str] = []
1423-
result = get_rag_toolgroups(vector_db_ids)
1448+
vector_store_ids: list[str] = []
1449+
result = get_rag_toolgroups(vector_store_ids)
14241450
assert result is None
14251451

1426-
vector_db_ids = ["Vector-DB-1", "Vector-DB-2"]
1427-
result = get_rag_toolgroups(vector_db_ids)
1452+
vector_store_ids = ["Vector-DB-1", "Vector-DB-2"]
1453+
result = get_rag_toolgroups(vector_store_ids)
14281454
assert result is not None
14291455
assert len(result) == 1
14301456
assert result[0]["name"] == "builtin::rag/knowledge_search"
1431-
assert result[0]["args"]["vector_db_ids"] == vector_db_ids
1457+
assert result[0]["args"]["vector_db_ids"] == vector_store_ids
14321458

14331459

14341460
@pytest.mark.asyncio
@@ -1649,9 +1675,11 @@ async def test_retrieve_response_no_tools_bypasses_mcp_and_rag(
16491675
mock_client, mock_agent = prepare_agent_mocks
16501676
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
16511677
mock_client.shields.list.return_value = []
1652-
mock_vector_db = mocker.Mock()
1653-
mock_vector_db.identifier = "VectorDB-1"
1654-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
1678+
mock_vector_store = mocker.Mock()
1679+
mock_vector_store.id = "VectorDB-1"
1680+
mock_vector_stores_response = mocker.Mock()
1681+
mock_vector_stores_response.data = [mock_vector_store]
1682+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
16551683

16561684
# Mock configuration with MCP servers
16571685
mcp_servers = [
@@ -1704,9 +1732,11 @@ async def test_retrieve_response_no_tools_false_preserves_functionality(
17041732
mock_client, mock_agent = prepare_agent_mocks
17051733
mock_agent.create_turn.return_value.output_message.content = "LLM answer"
17061734
mock_client.shields.list.return_value = []
1707-
mock_vector_db = mocker.Mock()
1708-
mock_vector_db.identifier = "VectorDB-1"
1709-
mock_client.vector_dbs.list.return_value = [mock_vector_db]
1735+
mock_vector_store = mocker.Mock()
1736+
mock_vector_store.id = "VectorDB-1"
1737+
mock_vector_stores_response = mocker.Mock()
1738+
mock_vector_stores_response.data = [mock_vector_store]
1739+
mock_client.vector_stores.list.return_value = mock_vector_stores_response
17101740

17111741
# Mock configuration with MCP servers
17121742
mcp_servers = [

0 commit comments

Comments
 (0)