Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/mainService/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

origins = [
"http://localhost:5173", # Frontend running on localhost (React, Vue, etc.)
"https://cite-me.vercel.app"
]


Expand Down Expand Up @@ -47,7 +48,7 @@ async def startup_event(app: FastAPI):

app.add_middleware(
CORSMiddleware,
allow_origins=origins, # Allow specific origins
allow_origins=["*"], # Allow specific origins. modify this to allow only the your desired origins
allow_credentials=True, # Allow cookies & authentication headers
allow_methods=["POST", "GET", "OPTIONS", "HEAD"], # Allow all HTTP methods (GET, POST, PUT, DELETE, etc.)
allow_headers=["*"], # Allow all headers
Expand Down
2 changes: 1 addition & 1 deletion backend/mainService/src/services/citation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def process_single_query(self, query: str) -> Dict[str, Any]:
Dict[str, Any]: The processed results

"""
logger.info(f"Processing query {query}")
logger.info(f"Processing query {query[:15]}")
search_results = await self.PC.hybrid_query(query=query, top_k=5)
formatted_results = format_for_rerank(search_results['matches'])
reranked_results = await rerank(matches=formatted_results, query=query, top_n=1, rank_fields=["page_content"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def _calculate_source_score(metric: Dict, source: Dict,
rerank_score = source["rerank_score"]

# Normalize rerank score to 0-1 range
normalized_rerank = min(max(rerank_score, 0), 1)
normalized_rerank = min(max(rerank_score, 0), 1)* 100

# Calculate weighted score and normalize to 0-100 range
weighted_score = round((normalized_rerank * rerank_weight +
credibility_score * credibility_weight) * 100, 2)
credibility_score * credibility_weight) , 2)

# Update the credibility score in the metric data
metric["data"]["credibility_score"] = weighted_score
Expand All @@ -54,7 +54,7 @@ async def get_credibility_metrics(sources: List[Dict]) -> List[Dict]:
return []

# Configure timeout
timeout = aiohttp.ClientTimeout(total=10)
timeout = aiohttp.ClientTimeout(total=20)

try:
async with aiohttp.ClientSession(timeout=timeout) as session:
Expand Down
1 change: 0 additions & 1 deletion backend/mainService/src/utils/format_rerank_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def filter_mixbread_results(
if doc.get("id") not in seen_ids and result.score >= benchmark:
seen_ids.add(doc.pop("id"))
doc["score"] = result.score
print(f"doc: {doc}")
unique_results.append(doc)
# with open("sample_output\\rerank_result_mixbread.json", "a") as f:
# json.dump(unique_results, f, indent=4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def test_calculate_overall_score_success():
assert isinstance(result, dict)
assert "overall_score" in result
assert "source_scores" in result
assert result["overall_score"] == 86.00 # (0.9 * 0.6 + 0.8 * 0.4) * 100
assert result["overall_score"] == 54.32 # ((0.9 *100 )*0.6 + 0.8 * 0.4)

@pytest.mark.asyncio
async def test_calculate_overall_score_empty():
Expand All @@ -113,7 +113,7 @@ async def test_calculate_overall_score_mixed_status():
result = await calculate_overall_score(credibility_metrics, sources_with_scores)
print(result)
assert len(result["source_scores"]) == 2
assert result["source_scores"][0] == 86.00
assert result["source_scores"][0] == 54.32

@pytest.mark.asyncio
async def test_calculate_overall_score_missing_data():
Expand Down
5 changes: 5 additions & 0 deletions backend/metricsService/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=your_redis_password_here
17 changes: 8 additions & 9 deletions backend/metricsService/src/utils/cache_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@
"""

from typing import Optional
import os
from redis import asyncio as aioredis
from src.utils.logging_config import get_logger

logger = get_logger(__name__)

# Redis connection settings
# REDIS_URL = "redis://localhost:6379"
# Redis connection settings from environment variables
redis_client: Optional[aioredis.Redis] = None

async def init_redis():
"""Initialize Redis connection"""
global redis_client
try:
redis_client = aioredis.Redis(
host='localhost',
port=6379,
db=0,
decode_responses=True
)


host=os.getenv('REDIS_HOST', 'localhost'),
port=int(os.getenv('REDIS_PORT', '6379')),
db=int(os.getenv('REDIS_DB', '0')),
password=os.getenv('REDIS_PASSWORD'),
decode_responses=True
)
except Exception as e:
logger.error(f"Failed to initialize Redis connection: {str(e)}")
raise
Expand Down