Skip to content

Commit e2f35f6

Browse files
committed
format
1 parent 8277086 commit e2f35f6

14 files changed

+129
-87
lines changed

examples/hybrid_search_example.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
Settings.CHROMA,
3535
persist_directory=persist_directory,
3636
collection_name=collection_name,
37-
search_type=Settings.SEARCH_SEMANTIC, # default — can be omitted
37+
search_type=Settings.SEARCH_SEMANTIC, # default — can be omitted
38+
)
39+
.with_llm(
40+
Settings.OLLAMA,
41+
model_name=model_name,
42+
system_prompt=Settings.DEFAULT_SYSTEM_PROMPT,
3843
)
39-
.with_llm(Settings.OLLAMA, model_name=model_name, system_prompt=Settings.DEFAULT_SYSTEM_PROMPT)
4044
.build_rag(k=5)
4145
)
4246
rag_semantic.vector_store.ingest(data_path=data_path)
@@ -54,7 +58,11 @@
5458
collection_name=collection_name + "_bm25",
5559
search_type=Settings.SEARCH_BM25,
5660
)
57-
.with_llm(Settings.OLLAMA, model_name=model_name, system_prompt=Settings.DEFAULT_SYSTEM_PROMPT)
61+
.with_llm(
62+
Settings.OLLAMA,
63+
model_name=model_name,
64+
system_prompt=Settings.DEFAULT_SYSTEM_PROMPT,
65+
)
5866
.build_rag(k=5)
5967
)
6068
rag_bm25.vector_store.ingest(data_path=data_path)
@@ -71,9 +79,13 @@
7179
persist_directory=persist_directory,
7280
collection_name=collection_name + "_hybrid",
7381
search_type=Settings.SEARCH_HYBRID,
74-
alpha=0.5, # weight of semantic vs BM25 in the RRF merge (0=BM25 only, 1=semantic only)
82+
alpha=0.5, # weight of semantic vs BM25 in the RRF merge (0=BM25 only, 1=semantic only)
83+
)
84+
.with_llm(
85+
Settings.OLLAMA,
86+
model_name=model_name,
87+
system_prompt=Settings.DEFAULT_SYSTEM_PROMPT,
7588
)
76-
.with_llm(Settings.OLLAMA, model_name=model_name, system_prompt=Settings.DEFAULT_SYSTEM_PROMPT)
7789
.build_rag(k=5)
7890
)
7991
rag_hybrid.vector_store.ingest(data_path=data_path)
@@ -93,7 +105,7 @@
93105
database=Settings.CHROMA,
94106
persist_directory=persist_directory,
95107
collection_name=collection_name + "_api",
96-
search_type=Settings.SEARCH_HYBRID, # <-- hybrid mode
108+
search_type=Settings.SEARCH_HYBRID, # <-- hybrid mode
97109
hybrid_alpha=0.5,
98110
)
99111

examples/langfuse_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,5 @@
8080
print(f"A: {response}")
8181

8282
print(
83-
"\nAll traces have been sent to Langfuse. "
84-
"Open your dashboard to inspect them."
83+
"\nAll traces have been sent to Langfuse. " "Open your dashboard to inspect them."
8584
)

examples/qdrant_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
# --- Configuration -----------------------------------------------------------
2525

26-
persist_directory = "./qdrantDb" # local mode — change to None + set host/port for remote
26+
persist_directory = (
27+
"./qdrantDb" # local mode — change to None + set host/port for remote
28+
)
2729
# host = "localhost" # remote mode
2830
# port = 6333 # remote mode (default)
2931

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
even though langgraph==1.0.5 does not expose the expected symbols.
44
Loaded automatically by both unittest and pytest before any test module.
55
"""
6+
67
import os
78
import sys
89
from unittest.mock import MagicMock

tests/tests_api/test_router.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def test_health(self):
3232

3333
def test_generate(self):
3434
self.pipeline.generate.return_value = "Paris is the capital of France."
35-
response = self.client.post("/generate", json={"question": "What is the capital of France?"})
35+
response = self.client.post(
36+
"/generate", json={"question": "What is the capital of France?"}
37+
)
3638
self.assertEqual(response.status_code, 200)
3739
self.assertEqual(response.json(), {"answer": "Paris is the capital of France."})
3840
self.pipeline.generate.assert_called_once_with("What is the capital of France?")
@@ -56,7 +58,9 @@ def test_ingest_missing_params(self):
5658
response = self.client.post("/ingest", json={})
5759
self.assertEqual(response.status_code, 400)
5860
detail = response.json()["detail"]
59-
self.assertTrue(any(k in detail for k in ("data_path", "file_paths", "github_url")))
61+
self.assertTrue(
62+
any(k in detail for k in ("data_path", "file_paths", "github_url"))
63+
)
6064

6165
def test_ingest_github(self):
6266
self.vector_store.ingest.return_value = None
@@ -66,7 +70,10 @@ def test_ingest_github(self):
6670
MockScrapper.return_value = instance
6771
response = self.client.post(
6872
"/ingest",
69-
json={"github_url": "https://github.com/example/repo", "github_branch": "main"},
73+
json={
74+
"github_url": "https://github.com/example/repo",
75+
"github_branch": "main",
76+
},
7077
)
7178
self.assertEqual(response.status_code, 200)
7279
instance.set_repositories.assert_called_once()
@@ -88,7 +95,9 @@ def test_ingest_file_paths(self):
8895

8996
def test_ingest_file_paths_missing_file(self):
9097
with patch("os.path.isfile", return_value=False):
91-
response = self.client.post("/ingest", json={"file_paths": ["/nonexistent/file.pdf"]})
98+
response = self.client.post(
99+
"/ingest", json={"file_paths": ["/nonexistent/file.pdf"]}
100+
)
92101
self.assertEqual(response.status_code, 500)
93102
self.assertIn("not found", response.json()["detail"].lower())
94103

@@ -116,7 +125,10 @@ def test_ingest_upload_no_files(self):
116125
# ── /collections ──────────────────────────────────────────────────────────
117126

118127
def test_collections(self):
119-
self.vector_store.get_available_collections.return_value = ["default", "project_x"]
128+
self.vector_store.get_available_collections.return_value = [
129+
"default",
130+
"project_x",
131+
]
120132
response = self.client.get("/collections")
121133
self.assertEqual(response.status_code, 200)
122134
self.assertEqual(response.json(), {"collections": ["default", "project_x"]})

tests/tests_api/test_server_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def test_to_vector_store_config_returns_correct_type(self):
7474
self.assertEqual(vs_config.collection_name, cfg.collection)
7575

7676
def test_to_vector_store_config_chroma_host(self):
77-
env = {**_clean_env(), "RAGLIGHT_CHROMA_HOST": "chromadb", "RAGLIGHT_CHROMA_PORT": "8000"}
77+
env = {
78+
**_clean_env(),
79+
"RAGLIGHT_CHROMA_HOST": "chromadb",
80+
"RAGLIGHT_CHROMA_PORT": "8000",
81+
}
7882
with patch.dict(os.environ, env, clear=True):
7983
cfg = ServerConfig()
8084
vs_config = cfg.to_vector_store_config()

tests/tests_embeddings/test_gemini_embeddings.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,64 @@
44
from ..test_config import TestsConfig
55
from google.genai import types
66

7+
78
class TestGeminiEmbeddings(unittest.TestCase):
8-
9+
910
@patch("raglight.embeddings.gemini_embeddings.Client")
1011
def test_model_load(self, MockClient: MagicMock):
1112
"""
1213
Test that the client is instantiated with the correct parameters.
1314
Note: The code uses Client(...) instead of configure().
1415
"""
1516
model = GeminiEmbeddingsModel(TestsConfig.GEMINI_EMBEDDING_MODEL)
16-
17+
1718
self.assertTrue(MockClient.called)
18-
19-
self.assertIsNotNone(model.model, "Model (genai client instance) should be loaded.")
19+
20+
self.assertIsNotNone(
21+
model.model, "Model (genai client instance) should be loaded."
22+
)
2023

2124
@patch("raglight.embeddings.gemini_embeddings.Client")
2225
def test_embed_documents(self, MockClient: MagicMock):
2326
"""Test document embedding with the correct task_type."""
2427
mock_client_instance = MockClient.return_value
25-
26-
mock_client_instance.embed_content.return_value = {'embedding': [[0.1, 0.2], [0.3, 0.4]]}
27-
28+
29+
mock_client_instance.embed_content.return_value = {
30+
"embedding": [[0.1, 0.2], [0.3, 0.4]]
31+
}
32+
2833
model = GeminiEmbeddingsModel(TestsConfig.GEMINI_EMBEDDING_MODEL)
2934
texts = ["doc1", "doc2"]
30-
35+
3136
result = model.embed_documents(texts)
32-
37+
3338
self.assertEqual(len(result), 2)
34-
39+
3540
mock_client_instance.embed_content.assert_called_with(
3641
model=TestsConfig.GEMINI_EMBEDDING_MODEL,
3742
content=texts,
38-
task_type="retrieval_document"
43+
task_type="retrieval_document",
3944
)
4045

4146
@patch("raglight.embeddings.gemini_embeddings.Client")
4247
def test_embed_query(self, MockClient: MagicMock):
4348
"""Test query embedding with the correct task_type."""
4449
mock_client_instance = MockClient.return_value
45-
mock_client_instance.embed_content.return_value = {'embedding': [0.1, 0.2]}
46-
50+
mock_client_instance.embed_content.return_value = {"embedding": [0.1, 0.2]}
51+
4752
model = GeminiEmbeddingsModel(TestsConfig.GEMINI_EMBEDDING_MODEL)
4853
text = "query"
49-
54+
5055
result = model.embed_query(text)
51-
56+
5257
self.assertEqual(len(result), 2)
53-
58+
5459
mock_client_instance.embed_content.assert_called_with(
5560
model=TestsConfig.GEMINI_EMBEDDING_MODEL,
5661
content=text,
57-
task_type="retrieval_query"
62+
task_type="retrieval_query",
5863
)
5964

65+
6066
if __name__ == "__main__":
61-
unittest.main()
67+
unittest.main()

tests/tests_embeddings/test_huggingface_embeddings.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77

88
class TestHuggingFaceEmbeddings(unittest.TestCase):
9-
9+
1010
@patch("raglight.embeddings.huggingface_embeddings.SentenceTransformer")
1111
def test_model_load(self, mock_transformer: MagicMock):
1212
"""Test SentenceTransformer model loading."""
1313
mock_transformer.return_value = MagicMock()
1414
embeddings = HuggingfaceEmbeddingsModel(TestsConfig.HUGGINGFACE_EMBEDDINGS)
15-
16-
15+
1716
self.assertIsNotNone(embeddings.model, "Model should be loaded successfully.")
1817
mock_transformer.assert_called_once_with(TestsConfig.HUGGINGFACE_EMBEDDINGS)
1918

@@ -22,14 +21,14 @@ def test_embed_documents(self, mock_transformer: MagicMock):
2221
"""Test document encoding."""
2322
mock_instance = mock_transformer.return_value
2423
mock_instance.encode.return_value = np.array([[0.1, 0.2], [0.3, 0.4]])
25-
24+
2625
embeddings = HuggingfaceEmbeddingsModel(TestsConfig.HUGGINGFACE_EMBEDDINGS)
2726
result = embeddings.embed_documents(["text1", "text2"])
28-
27+
2928
self.assertIsInstance(result, list)
3029
self.assertIsInstance(result[0], list)
3130
mock_instance.encode.assert_called_with(["text1", "text2"])
3231

3332

3433
if __name__ == "__main__":
35-
unittest.main()
34+
unittest.main()

tests/tests_embeddings/test_ollama_embeddings.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TestOllamaEmbeddings(unittest.TestCase):
8-
8+
99
@patch("raglight.embeddings.ollama_embeddings.Client")
1010
def test_model_load(self, mock_client: MagicMock):
1111
"""Test Ollama client initialization."""
@@ -18,40 +18,32 @@ def test_model_load(self, mock_client: MagicMock):
1818
def test_embed_documents(self, mock_client: MagicMock):
1919
"""Test batch embedding with .embed() method."""
2020
mock_instance = mock_client.return_value
21-
mock_instance.embed.return_value = {
22-
"embeddings": [[0.1, 0.2], [0.3, 0.4]]
23-
}
24-
21+
mock_instance.embed.return_value = {"embeddings": [[0.1, 0.2], [0.3, 0.4]]}
22+
2523
model = OllamaEmbeddingsModel(TestsConfig.OLLAMA_EMBEDDING_MODEL)
2624
texts = ["doc1", "doc2"]
2725
result = model.embed_documents(texts)
28-
26+
2927
self.assertEqual(len(result), 2)
3028
mock_instance.embed.assert_called_with(
31-
model=TestsConfig.OLLAMA_EMBEDDING_MODEL,
32-
input=texts,
33-
options=model.options
29+
model=TestsConfig.OLLAMA_EMBEDDING_MODEL, input=texts, options=model.options
3430
)
3531

3632
@patch("raglight.embeddings.ollama_embeddings.Client")
3733
def test_embed_query(self, mock_client: MagicMock):
3834
"""Test single embedding with .embeddings() method."""
3935
mock_instance = mock_client.return_value
40-
mock_instance.embeddings.return_value = {
41-
"embedding": [0.9, 0.9]
42-
}
43-
36+
mock_instance.embeddings.return_value = {"embedding": [0.9, 0.9]}
37+
4438
model = OllamaEmbeddingsModel(TestsConfig.OLLAMA_EMBEDDING_MODEL)
4539
text = "query text"
4640
result = model.embed_query(text)
47-
41+
4842
self.assertEqual(result, [0.9, 0.9])
4943
mock_instance.embeddings.assert_called_with(
50-
model=TestsConfig.OLLAMA_EMBEDDING_MODEL,
51-
prompt=text,
52-
options=model.options
44+
model=TestsConfig.OLLAMA_EMBEDDING_MODEL, prompt=text, options=model.options
5345
)
5446

5547

5648
if __name__ == "__main__":
57-
unittest.main()
49+
unittest.main()

0 commit comments

Comments
 (0)