Skip to content

Commit 1ea0ab9

Browse files
committed
Use weaviate config
1 parent 328b655 commit 1ea0ab9

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

dockers/llm.rag.service/config.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from pydantic_settings import BaseSettings
2-
from pydantic import Field
3-
41
from typing import Optional
52

3+
from pydantic import Field, field_validator
4+
from pydantic_settings import BaseSettings
65

76
WEAVIATE_HYBRID_ALPHA_DEFAULT = 0.5
87

@@ -11,7 +10,7 @@ def validate_float(value):
1110
if type(value) == float:
1211
return value
1312
try:
14-
return float(value.strip("'").strip("\""))
13+
return float(value.strip("'").strip('"'))
1514
except (TypeError, ValueError):
1615
raise ValueError("Value must be convertible to a float")
1716

@@ -34,9 +33,28 @@ class WeaviateSettings(BaseSettings):
3433
alias="WEAVIATE_HYBRID_ALPHA",
3534
)
3635

36+
@field_validator("weaviate_hybrid_search_alpha", mode="before")
37+
@classmethod
38+
def validate_weaviate_hybrid_search_alpha(cls, v):
39+
return validate_float(v)
40+
3741
class Config:
3842
env_file = ".env"
3943
extra = "ignore"
4044

4145
def is_set(self) -> bool:
42-
return all([self.weaviate_uri, self.weaviate_grpc_uri, self.weaviate_index_name])
46+
return all(
47+
[self.weaviate_uri, self.weaviate_grpc_uri, self.weaviate_index_name]
48+
)
49+
50+
def get_weaviate_uri(self):
51+
return self.weaviate_uri.split(":")[0]
52+
53+
def get_weaviate_port(self):
54+
return int(self.weaviate_uri.split(":")[1])
55+
56+
def get_weaviate_grpc_uri(self):
57+
return self.weaviate_grpc_uri.split(":")[0]
58+
59+
def get_weaviate_grpc_port(self):
60+
return int(self.weaviate_grpc_uri.split(":")[1])

dockers/llm.rag.service/search.py

Whitespace-only changes.

dockers/llm.rag.service/serverragllm_csv_to_weaviate_local.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
from common import get_answer_with_settings_with_weaviate_filter
32+
from config import WeaviateSettings
3233

3334
SYSTEM_PROMPT_DEFAULT = """You are a specialized support ticket assistant. Format your responses following these rules:
3435
1. Answer the provided question only using the provided context.
@@ -47,31 +48,29 @@ def setup(
4748
model_id: str,
4849
max_tokens: int,
4950
model_temperature: float,
50-
weaviate_url: str,
51-
weaviate_grpc_url: str,
52-
weaviate_index: str,
5351
embedding_model_name: str,
5452
sql_search_db_and_model_path: str,
55-
alpha: float,
5653
max_context_length: int,
5754
sql_ticket_source: str,
5855
):
5956
app = FastAPI()
6057

58+
weaviate_settings = WeaviateSettings()
59+
6160
embeddings = HuggingFaceEmbeddings(model_name=embedding_model_name)
6261

6362
weaviate_client = weaviate.connect_to_custom(
64-
http_host=weaviate_url.split(":")[0],
65-
http_port=int(weaviate_url.split(":")[1]),
63+
http_host=weaviate_settings.get_weaviate_uri(),
64+
http_port=weaviate_settings.get_weaviate_port(),
6665
http_secure=False,
67-
grpc_host=weaviate_grpc_url.split(":")[0],
68-
grpc_port=int(weaviate_grpc_url.split(":")[1]),
66+
grpc_host=weaviate_settings.get_weaviate_grpc_uri(),
67+
grpc_port=weaviate_settings.get_weaviate_grpc_port(),
6968
grpc_secure=False,
7069
)
7170

7271
vectorstore = WeaviateVectorStore(
7372
client=weaviate_client,
74-
index_name=weaviate_index,
73+
index_name=weaviate_settings.weaviate_index_name,
7574
text_key="text",
7675
embedding=embeddings,
7776
)
@@ -98,7 +97,7 @@ def setup(
9897
relevant_docs=relevant_docs,
9998
llm_server_url=llm_server_url,
10099
sql_search_db_and_model_path=sql_search_db_and_model_path,
101-
alpha=alpha,
100+
alpha=weaviate_settings.weaviate_hybrid_search_alpha,
102101
max_context_length=max_context_length,
103102
sql_ticket_source=sql_ticket_source,
104103
)
@@ -161,12 +160,8 @@ def read_item(question: Union[str, None] = None):
161160
model_id,
162161
max_tokens,
163162
model_temperature,
164-
weaviate_url,
165-
weaviate_grpc_url,
166-
weaviate_index,
167163
embedding_model_name,
168164
sql_search_db_and_model_path,
169-
alpha,
170165
max_context_length,
171166
sql_ticket_source,
172167
)

0 commit comments

Comments
 (0)