Skip to content

Commit dde0743

Browse files
authored
Merge pull request #638 from tisnik/lcore-642-byok-rag-configuration
LCORE-642: BYOK RAG configuration
2 parents 690a6bc + 643cdd5 commit dde0743

File tree

8 files changed

+499
-308
lines changed

8 files changed

+499
-308
lines changed

docs/config.png

5.21 KB
Loading

docs/config.puml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class "AuthenticationConfiguration" as src.models.config.AuthenticationConfigura
1919
class "AuthorizationConfiguration" as src.models.config.AuthorizationConfiguration {
2020
access_rules : Optional[list[AccessRule]]
2121
}
22+
class "ByokRag" as src.models.config.ByokRag {
23+
db_path : Annotated
24+
embedding_dimension : Annotated
25+
embedding_model : Annotated
26+
rag_id : Annotated
27+
rag_type : Annotated
28+
vector_db_id : Annotated
29+
}
2230
class "CORSConfiguration" as src.models.config.CORSConfiguration {
2331
allow_credentials : bool
2432
allow_headers : list[str]
@@ -29,6 +37,7 @@ class "CORSConfiguration" as src.models.config.CORSConfiguration {
2937
class "Configuration" as src.models.config.Configuration {
3038
authentication : Optional[AuthenticationConfiguration]
3139
authorization : Optional[AuthorizationConfiguration]
40+
byok_rag : Optional[list[ByokRag]]
3241
conversation_cache : Optional[ConversationCacheConfiguration]
3342
customization : Optional[Customization]
3443
database : Optional[DatabaseConfiguration]
@@ -155,6 +164,7 @@ class "UserDataCollection" as src.models.config.UserDataCollection {
155164
src.models.config.AccessRule --|> src.models.config.ConfigurationBase
156165
src.models.config.AuthenticationConfiguration --|> src.models.config.ConfigurationBase
157166
src.models.config.AuthorizationConfiguration --|> src.models.config.ConfigurationBase
167+
src.models.config.ByokRag --|> src.models.config.ConfigurationBase
158168
src.models.config.CORSConfiguration --|> src.models.config.ConfigurationBase
159169
src.models.config.Configuration --|> src.models.config.ConfigurationBase
160170
src.models.config.ConversationCacheConfiguration --|> src.models.config.ConfigurationBase

docs/config.svg

Lines changed: 329 additions & 308 deletions
Loading

src/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,16 @@
127127
CACHE_TYPE_SQLITE = "sqlite"
128128
CACHE_TYPE_POSTGRES = "postgres"
129129
CACHE_TYPE_NOOP = "noop"
130+
131+
# BYOK RAG
132+
# Default RAG type for bring-your-own-knowledge RAG configurations, that type
133+
# needs to be supported by Llama Stack
134+
DEFAULT_RAG_TYPE = "inline::faiss"
135+
136+
# Default sentence transformer model for embedding generation, that type needs
137+
# to be supported by Llama Stack and configured properly in providers and
138+
# models sections
139+
DEFAULT_EMBEDDING_MODEL = "sentence-transformers/all-mpnet-base-v2"
140+
141+
# Default embedding vector dimension for the sentence transformer model
142+
DEFAULT_EMBEDDING_DIMENSION = 768

src/models/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ConfigDict,
1414
Field,
1515
model_validator,
16+
constr,
1617
FilePath,
1718
AnyHttpUrl,
1819
PositiveInt,
@@ -545,6 +546,19 @@ def check_cache_configuration(self) -> Self:
545546
return self
546547

547548

549+
class ByokRag(ConfigurationBase):
550+
"""BYOK RAG configuration."""
551+
552+
rag_id: constr(min_length=1) # type:ignore
553+
rag_type: constr(min_length=1) = constants.DEFAULT_RAG_TYPE # type:ignore
554+
embedding_model: constr(min_length=1) = ( # type:ignore
555+
constants.DEFAULT_EMBEDDING_MODEL
556+
)
557+
embedding_dimension: PositiveInt = constants.DEFAULT_EMBEDDING_DIMENSION
558+
vector_db_id: constr(min_length=1) # type:ignore
559+
db_path: FilePath
560+
561+
548562
class Configuration(ConfigurationBase):
549563
"""Global service configuration."""
550564

@@ -563,6 +577,7 @@ class Configuration(ConfigurationBase):
563577
conversation_cache: ConversationCacheConfiguration = Field(
564578
default_factory=ConversationCacheConfiguration
565579
)
580+
byok_rag: list[ByokRag] = Field(default_factory=list)
566581

567582
def dump(self, filename: str = "configuration.json") -> None:
568583
"""Dump actual configuration into JSON file."""

tests/configuration/rag.txt

Whitespace-only changes.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""Unit tests for ByokRag model."""
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
from pydantic import ValidationError
8+
9+
from models.config import ByokRag
10+
11+
from constants import (
12+
DEFAULT_RAG_TYPE,
13+
DEFAULT_EMBEDDING_MODEL,
14+
DEFAULT_EMBEDDING_DIMENSION,
15+
)
16+
17+
18+
def test_byok_rag_configuration_default_values() -> None:
19+
"""Test the ByokRag constructor."""
20+
21+
byok_rag = ByokRag(
22+
rag_id="rag_id",
23+
vector_db_id="vector_db_id",
24+
db_path="tests/configuration/rag.txt",
25+
)
26+
assert byok_rag is not None
27+
assert byok_rag.rag_id == "rag_id"
28+
assert byok_rag.rag_type == DEFAULT_RAG_TYPE
29+
assert byok_rag.embedding_model == DEFAULT_EMBEDDING_MODEL
30+
assert byok_rag.embedding_dimension == DEFAULT_EMBEDDING_DIMENSION
31+
assert byok_rag.vector_db_id == "vector_db_id"
32+
assert byok_rag.db_path == Path("tests/configuration/rag.txt")
33+
34+
35+
def test_byok_rag_configuration_nondefault_values() -> None:
36+
"""Test the ByokRag constructor."""
37+
38+
byok_rag = ByokRag(
39+
rag_id="rag_id",
40+
rag_type="rag_type",
41+
embedding_model="embedding_model",
42+
embedding_dimension=1024,
43+
vector_db_id="vector_db_id",
44+
db_path="tests/configuration/rag.txt",
45+
)
46+
assert byok_rag is not None
47+
assert byok_rag.rag_id == "rag_id"
48+
assert byok_rag.rag_type == "rag_type"
49+
assert byok_rag.embedding_model == "embedding_model"
50+
assert byok_rag.embedding_dimension == 1024
51+
assert byok_rag.vector_db_id == "vector_db_id"
52+
assert byok_rag.db_path == Path("tests/configuration/rag.txt")
53+
54+
55+
def test_byok_rag_configuration_wrong_dimension() -> None:
56+
"""Test the ByokRag constructor."""
57+
58+
with pytest.raises(ValidationError, match="should be greater than 0"):
59+
_ = ByokRag(
60+
rag_id="rag_id",
61+
rag_type="rag_type",
62+
embedding_model="embedding_model",
63+
embedding_dimension=-1024,
64+
vector_db_id="vector_db_id",
65+
db_path="tests/configuration/rag.txt",
66+
)
67+
68+
69+
def test_byok_rag_configuration_empty_rag_id() -> None:
70+
"""Test the ByokRag constructor."""
71+
72+
with pytest.raises(
73+
ValidationError, match="String should have at least 1 character"
74+
):
75+
_ = ByokRag(
76+
rag_id="",
77+
rag_type="rag_type",
78+
embedding_model="embedding_model",
79+
embedding_dimension=1024,
80+
vector_db_id="vector_db_id",
81+
db_path="tests/configuration/rag.txt",
82+
)
83+
84+
85+
def test_byok_rag_configuration_empty_rag_type() -> None:
86+
"""Test the ByokRag constructor."""
87+
88+
with pytest.raises(
89+
ValidationError, match="String should have at least 1 character"
90+
):
91+
_ = ByokRag(
92+
rag_id="rag_id",
93+
rag_type="",
94+
embedding_model="embedding_model",
95+
embedding_dimension=1024,
96+
vector_db_id="vector_db_id",
97+
db_path="tests/configuration/rag.txt",
98+
)
99+
100+
101+
def test_byok_rag_configuration_empty_embedding_model() -> None:
102+
"""Test the ByokRag constructor."""
103+
104+
with pytest.raises(
105+
ValidationError, match="String should have at least 1 character"
106+
):
107+
_ = ByokRag(
108+
rag_id="rag_id",
109+
rag_type="rag_type",
110+
embedding_model="",
111+
embedding_dimension=1024,
112+
vector_db_id="vector_db_id",
113+
db_path="tests/configuration/rag.txt",
114+
)
115+
116+
117+
def test_byok_rag_configuration_empty_vector_db_id() -> None:
118+
"""Test the ByokRag constructor."""
119+
120+
with pytest.raises(
121+
ValidationError, match="String should have at least 1 character"
122+
):
123+
_ = ByokRag(
124+
rag_id="rag_id",
125+
rag_type="rag_type",
126+
embedding_model="embedding_model",
127+
embedding_dimension=1024,
128+
vector_db_id="",
129+
db_path="tests/configuration/rag.txt",
130+
)

tests/unit/models/config/test_dump_configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def test_dump_configuration(tmp_path) -> None:
8888
assert "customization" in content
8989
assert "inference" in content
9090
assert "database" in content
91+
assert "byok_rag" in content
9192

9293
# check the whole deserialized JSON file content
9394
assert content == {
@@ -169,6 +170,7 @@ def test_dump_configuration(tmp_path) -> None:
169170
"sqlite": None,
170171
"type": None,
171172
},
173+
"byok_rag": [],
172174
}
173175

174176

0 commit comments

Comments
 (0)