Fixed warnings from pylint

This commit is contained in:
Jan Mrna
2025-11-06 10:58:18 +01:00
parent 7010edae44
commit ee8a8ad170
2 changed files with 45 additions and 22 deletions

34
main.py
View File

@@ -1,9 +1,15 @@
import argparse
#pylint: disable=broad-exception-caught
"""
Semantic search tool main script.
Provides command-line interface and web server for creating, adding and querying the database.
"""
import sys
from pathlib import Path
import tempfile
import numpy as np
import argparse
from typing import Final
from pathlib import Path
import numpy as np
import db
@@ -88,17 +94,10 @@ def test_database():
# Test embedding functionality
print("\n5. Testing embedding functionality (Ollama API server)...")
try:
test_embedding = db._embed("This is a test text for embedding.")
print(
f" Embedding test PASSED: Generated vector of shape {test_embedding.shape}"
)
ollama_running = True
except Exception as e:
print(
f" Embedding test FAILED: {e}\n Did you start ollama docker image?"
)
ollama_running = False
embedding_ok = db.test_embedding()
print(f" Embedding test {'PASSED' if embedding_ok else 'FAILED'}")
if not embedding_ok:
print(" Did you start ollama docker image?")
# Summary
all_good = (
@@ -106,7 +105,7 @@ def test_database():
and records_match
and vectors_equal
and records_equal
and ollama_running
and embedding_ok
)
print(f"\n✅ Test {'PASSED' if all_good else 'FAILED'}")
@@ -204,6 +203,8 @@ def query(db_path: str, query_text: str):
def start_web_server(db_path: str, host: str = "127.0.0.1", port: int = 5000):
"""Start a web server for the semantic search tool."""
try:
# here we intentionally import inside the function to avoid Flask dependency for CLI usage
# pylint: disable=import-outside-toplevel
from flask import Flask, request, jsonify, render_template, send_file
except ImportError:
print("❌ Flask not found. Please install it first:")
@@ -282,6 +283,9 @@ def start_web_server(db_path: str, host: str = "127.0.0.1", port: int = 5000):
def main():
"""
Main function to parse command-line arguments and execute commands.
"""
parser = argparse.ArgumentParser(
description="Semantic Search Tool",
formatter_class=argparse.RawDescriptionHelpFormatter,