Skip to content

Commit bbccaa0

Browse files
committed
Parse index name from chunk metadata source attribute
1 parent 36c2ae2 commit bbccaa0

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/utils/responses.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,11 @@ def _resolve_source_for_result(
846846
if attr_store_id:
847847
return rag_id_mapping.get(attr_store_id, attr_store_id)
848848

849+
# Fallback: read index name embedded directly by rag-content
850+
attr_source: Optional[str] = attributes.get("source")
851+
if attr_source:
852+
return rag_id_mapping.get(attr_source, attr_source)
853+
849854
return None
850855

851856

tests/unit/utils/test_responses.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,69 @@ def test_multiple_stores_attribute_not_in_mapping(
20442044
)
20452045
assert source == "vs-unknown"
20462046

2047+
def test_multiple_stores_source_attribute_fallback(
2048+
self, mocker: MockerFixture
2049+
) -> None:
2050+
"""Test resolution falls back to source attribute when no vector_store_id."""
2051+
mock_result = mocker.Mock()
2052+
mock_result.filename = "file-abc123"
2053+
mock_result.attributes = {"source": "ocp-documentation"}
2054+
2055+
source = _resolve_source_for_result(
2056+
mock_result,
2057+
["vs-001", "vs-002"],
2058+
{"ocp-documentation": "ocp-4.18-docs"},
2059+
)
2060+
assert source == "ocp-4.18-docs"
2061+
2062+
def test_multiple_stores_source_attribute_unmapped(
2063+
self, mocker: MockerFixture
2064+
) -> None:
2065+
"""Test resolution returns raw source attribute when not in mapping."""
2066+
mock_result = mocker.Mock()
2067+
mock_result.filename = "file-abc123"
2068+
mock_result.attributes = {"source": "custom-index"}
2069+
2070+
source = _resolve_source_for_result(
2071+
mock_result,
2072+
["vs-001", "vs-002"],
2073+
{},
2074+
)
2075+
assert source == "custom-index"
2076+
2077+
def test_multiple_stores_vector_store_id_preferred_over_source(
2078+
self, mocker: MockerFixture
2079+
) -> None:
2080+
"""Test vector_store_id takes precedence over source attribute."""
2081+
mock_result = mocker.Mock()
2082+
mock_result.filename = "file-abc123"
2083+
mock_result.attributes = {
2084+
"vector_store_id": "vs-002",
2085+
"source": "should-not-be-used",
2086+
}
2087+
2088+
source = _resolve_source_for_result(
2089+
mock_result,
2090+
["vs-001", "vs-002"],
2091+
{"vs-002": "rhel-9-docs"},
2092+
)
2093+
assert source == "rhel-9-docs"
2094+
2095+
def test_multiple_stores_no_vector_store_id_no_source(
2096+
self, mocker: MockerFixture
2097+
) -> None:
2098+
"""Test resolution returns None when neither vector_store_id nor source present."""
2099+
mock_result = mocker.Mock()
2100+
mock_result.filename = "file-abc123"
2101+
mock_result.attributes = {"title": "some doc"}
2102+
2103+
source = _resolve_source_for_result(
2104+
mock_result,
2105+
["vs-001", "vs-002"],
2106+
{"vs-001": "ocp-docs"},
2107+
)
2108+
assert source is None
2109+
20472110

20482111
class TestBuildChunkAttributes:
20492112
"""Tests for _build_chunk_attributes function."""

0 commit comments

Comments
 (0)