Skip to content

Commit d673a63

Browse files
committed
fix(linter): format and lint errors
1 parent f59188e commit d673a63

File tree

6 files changed

+33
-26
lines changed

6 files changed

+33
-26
lines changed

src/flare_ai_rag/retriever/qdrant_retriever.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ def __init__(
2222
@override
2323
def semantic_search(self, query: str, top_k: int = 5) -> list[dict]:
2424
"""
25-
Perform semantic search by converting the query into a vector and searching in Qdrant.
25+
Perform semantic search by converting the query into a vector
26+
and searching in Qdrant.
2627
2728
:param query: The input query.
2829
:param top_k: Number of top results to return.
2930
:return: A list of dictionaries, each representing a retrieved document.
3031
"""
31-
# Convert the query into a vector embedding using the SentenceTransformer instance.
32+
# Convert the query into a vector embedding using the
33+
# SentenceTransformer instance.
3234
query_vector = self.embedding_model.encode(query)
3335

3436
# Search Qdrant for similar vectors.
@@ -41,11 +43,11 @@ def semantic_search(self, query: str, top_k: int = 5) -> list[dict]:
4143
# Process and return results.
4244
output = []
4345
for hit in results:
44-
output.append(
45-
{
46-
"text": hit.payload.get("text", ""),
47-
"score": hit.score,
48-
"metadata": {k: v for k, v in hit.payload.items() if k != "text"},
49-
}
50-
)
46+
if hit.payload:
47+
text = hit.payload.get("text", "")
48+
metadata = {k: v for k, v in hit.payload.items() if k != "text"}
49+
else:
50+
text = ""
51+
metadata = ""
52+
output.append({"text": text, "score": hit.score, "metadata": metadata})
5153
return output

src/flare_ai_rag/router/config.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
from dataclasses import dataclass
22

33
from flare_ai_rag.openrouter.model import Model
4-
5-
BASE_PROMPT = """You are a query router. Analyze the query below and classify it by returning exactly one of these values—without any additional text:\n\n
6-
7-
- **{answer_option}**: Use this if the query is clear, specific, and can be answered with factual information.\n
8-
- **{clarify_option}**: Use this if the query is ambiguous, vague, or needs additional context.\n
9-
- **{reject_option}**: Use this if the query is inappropriate, harmful, or completely out of scope.\n\n
10-
11-
Query: {query}\n\n
12-
13-
Return exactly one word: ANSWER, CLARIFY, or REJECT.
14-
"""
4+
from flare_ai_rag.router.prompts import BASE_PROMPT
155

166

177
@dataclass(frozen=True)

src/flare_ai_rag/router/prompts.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Final
2+
3+
BASE_PROMPT: Final = """
4+
You are a query router. Analyze the query below and classify it by returning exactly one of these values—without any additional text:\n\n
5+
6+
- **{answer_option}**: Use this if the query is clear, specific, and can be answered with factual information.\n
7+
- **{clarify_option}**: Use this if the query is ambiguous, vague, or needs additional context.\n
8+
- **{reject_option}**: Use this if the query is inappropriate, harmful, or completely out of scope.\n\n
9+
10+
Query: {query}\n\n
11+
12+
Return exactly one word: ANSWER, CLARIFY, or REJECT.
13+
"""

src/flare_ai_rag/router/router.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import override
2+
13
from flare_ai_rag.openrouter.client import OpenRouterClient
24
from flare_ai_rag.router.base_router import BaseQueryRouter
35
from flare_ai_rag.router.config import RouterConfig
@@ -9,7 +11,7 @@ class QueryRouter(BaseQueryRouter):
911
classify a query as ANSWER, CLARIFY, or REJECT.
1012
"""
1113

12-
def __init__(self, api_key: str, config: RouterConfig):
14+
def __init__(self, api_key: str, config: RouterConfig) -> None:
1315
"""
1416
Initialize the router with an API key and model name.
1517
:param api_key: Your OpenRouter API key.
@@ -18,6 +20,7 @@ def __init__(self, api_key: str, config: RouterConfig):
1820
self.config = config
1921
self.client = OpenRouterClient(api_key=api_key)
2022

23+
@override
2124
def route_query(self, query: str) -> str:
2225
"""
2326
Analyze the query using the configured prompt and classify it.

tests/test_generate_collection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import pandas as pd
32
import structlog
43
from qdrant_client import QdrantClient
@@ -18,7 +17,7 @@ def generate_collection(
1817
client: QdrantClient,
1918
qdrant_config: QdrantConfig,
2019
collection_name: str,
21-
):
20+
) -> None:
2221
"""Routine for generating a Qdrant collection for a specific CSV file type."""
2322
# Create the collection.
2423
create_collection(client, collection_name, qdrant_config.vector_size)
@@ -45,7 +44,7 @@ def generate_collection(
4544
# Compute the embedding for the document content.
4645
embedding = embedding_model.encode(content).tolist()
4746
except Exception as e:
48-
logger.error(
47+
logger.exception(
4948
"Error encoding document.", filename=row["Filename"], error=str(e)
5049
)
5150
continue
@@ -73,7 +72,7 @@ def generate_collection(
7372
logger.warning("No valid documents found to insert.")
7473

7574

76-
def main():
75+
def main() -> None:
7776
# Load Qdrant config
7877
config_json = loader.load_json(config.input_path / "input_parameters.json")
7978
qdrant_config = QdrantConfig.load(config_json["qdrant_config"])

tests/test_qdrant_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
logger = structlog.get_logger(__name__)
1010

1111

12-
def main():
12+
def main() -> None:
1313
# Load Qdrant config
1414
config_json = loader.load_json(config.input_path / "input_parameters.json")
1515
qdrant_config = QdrantConfig.load(config_json["qdrant_config"])

0 commit comments

Comments
 (0)