open-notebook/api/search_service.py
Luis Novo b7e656a319
Version 1 (#160)
New front-end
Launch Chat API
Manage Sources
Enable re-embedding of all contents
Sources can be added without a notebook now
Improved settings
Enable model selector on all chats
Background processing for better experience
Dark mode
Improved Notes

Improved Docs: 
- Remove all Streamlit references from documentation
- Update deployment guides with React frontend setup
- Fix Docker environment variables format (SURREAL_URL, SURREAL_PASSWORD)
- Update docker image tag from :latest to :v1-latest
- Change navigation references (Settings → Models to just Models)
- Update development setup to include frontend npm commands
- Add MIGRATION.md guide for users upgrading from Streamlit
- Update quick-start guide with correct environment variables
- Add port 5055 documentation for API access
- Update project structure to reflect frontend/ directory
- Remove outdated source-chat documentation files
2025-10-18 12:46:22 -03:00

58 lines
No EOL
1.5 KiB
Python

"""
Search service layer using API.
"""
from typing import Any, Dict, List, Union
from loguru import logger
from api.client import api_client
class SearchService:
"""Service layer for search operations using API."""
def __init__(self):
logger.info("Using API for search operations")
def search(
self,
query: str,
search_type: str = "text",
limit: int = 100,
search_sources: bool = True,
search_notes: bool = True,
minimum_score: float = 0.2
) -> List[Dict[str, Any]]:
"""Search the knowledge base."""
response = api_client.search(
query=query,
search_type=search_type,
limit=limit,
search_sources=search_sources,
search_notes=search_notes,
minimum_score=minimum_score
)
if isinstance(response, dict):
return response.get("results", [])
return []
def ask_knowledge_base(
self,
question: str,
strategy_model: str,
answer_model: str,
final_answer_model: str
) -> Union[Dict[Any, Any], List[Dict[Any, Any]]]:
"""Ask the knowledge base a question."""
response = api_client.ask_simple(
question=question,
strategy_model=strategy_model,
answer_model=answer_model,
final_answer_model=final_answer_model
)
return response
# Global service instance
search_service = SearchService()