Skip to content
Open
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
34 changes: 0 additions & 34 deletions backend/ollama_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,37 +166,3 @@ def chat_stream(self, message: str, model: str = "llama3.2", conversation_histor
except requests.exceptions.RequestException as e:
yield f"Connection error: {e}"

def main():
"""Test the Ollama client"""
client = OllamaClient()

# Check if Ollama is running
if not client.is_ollama_running():
print("❌ Ollama is not running. Please start Ollama first.")
print("Install: https://ollama.ai")
print("Run: ollama serve")
return

print("✅ Ollama is running!")

# List available models
models = client.list_models()
print(f"Available models: {models}")

# Try to use llama3.2, pull if needed
model_name = "llama3.2"
if model_name not in [m.split(":")[0] for m in models]:
print(f"Model {model_name} not found. Pulling...")
if client.pull_model(model_name):
print(f"✅ Model {model_name} pulled successfully!")
else:
print(f"❌ Failed to pull model {model_name}")
return

# Test chat
print("\n🤖 Testing chat...")
response = client.chat("Hello! Can you tell me a short joke?", model_name)
print(f"AI: {response}")

if __name__ == "__main__":
main()
29 changes: 1 addition & 28 deletions backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,6 @@ def handle_index_documents(self, session_id: str):
print(f"❌ Exception during indexing: {str(e)}")
self.send_json_response({"error": f"An unexpected error occurred: {str(e)}"}, status_code=500)

def handle_pdf_upload(self, session_id: str):
"""
Processes PDF files: extracts text and stores it in the database.
DEPRECATED: This is the old method. Use handle_file_upload instead.
"""
# This function is now deprecated in favor of the new indexing workflow
# but is kept for potential legacy/compatibility reasons.
# For new functionality, it should not be used.
self.send_json_response({
"warning": "This upload method is deprecated. Use the new file upload and indexing flow.",
"message": "No action taken."
}, status_code=410) # 410 Gone

def handle_get_models(self):
"""Get available models from both Ollama and HuggingFace, grouped by capability"""
try:
Expand Down Expand Up @@ -907,15 +894,9 @@ def handle_build_index(self, index_id: str):
# Set per-index overview file path
overview_path = f"index_store/overviews/{index_id}.jsonl"

# Ensure config_override includes overview_path
def ensure_overview_path(cfg: dict):
cfg["overview_path"] = overview_path

# we'll inject later when we build config_override

# Delegate to advanced RAG API same as session indexing
rag_api_url = "http://localhost:8001/index"
import requests, json as _json
import requests
# Use the index's dedicated LanceDB table so retrieval matches
table_name = index.get("vector_table_name")
payload = {
Expand Down Expand Up @@ -1098,14 +1079,6 @@ def main():
print(f"❌ Error initializing PDF processor: {e}")
print("⚠️ PDF processing disabled - server will run without RAG functionality")

# Set a global reference to the initialized processor if needed elsewhere
global pdf_processor
pdf_processor = pdf_module.simple_pdf_processor
if pdf_processor:
print("✅ Global PDF processor initialized")
else:
print("⚠️ PDF processing disabled - server will run without RAG functionality")

# Cleanup empty sessions on startup
print("🧹 Cleaning up empty sessions...")
cleanup_count = db.cleanup_empty_sessions()
Expand Down
13 changes: 0 additions & 13 deletions backend/simple_pdf_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,3 @@ def initialize_simple_pdf_processor():
print(f"❌ Failed to initialize PDF processor: {str(e)}")
simple_pdf_processor = None

def get_simple_pdf_processor():
"""Get the global PDF processor instance"""
global simple_pdf_processor
if simple_pdf_processor is None:
initialize_simple_pdf_processor()
return simple_pdf_processor

if __name__ == "__main__":
# Test the simple PDF processor
print("🧪 Testing simple PDF processor...")

processor = SimplePDFProcessor()
print("✅ Simple PDF processor test completed!")
12 changes: 0 additions & 12 deletions rag_system/agent/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,6 @@ async def _run_async(self, query: str, table_name: str = None, session_id: str =
# 🚀 NEW: Get conversation history
history = self.chat_histories.get(session_id, []) if session_id else []

# 🔄 Refresh overviews for this session if available
# if session_id and session_id != getattr(self, "_current_overview_session", None):
# candidate_path = os.path.join("index_store", "overviews", f"{session_id}.jsonl")
# if os.path.exists(candidate_path):
# self._load_overviews(candidate_path)
# self._current_overview_session = session_id
# else:
# # Fall back to global overviews if per-session file not found
# if self._current_overview_session != "GLOBAL":
# self._load_overviews(self._global_overview_path)
# self._current_overview_session = "GLOBAL"

query_type = await self._triage_query_async(query, history)
print(f"🎯 ROUTING DEBUG: Final triage decision: '{query_type}'")
print(f"Agent Triage Decision: '{query_type}'")
Expand Down
25 changes: 7 additions & 18 deletions rag_system/api_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import http.server
import socketserver
from urllib.parse import urlparse, parse_qs
from urllib.parse import urlparse
import os
import requests
import sys
Expand Down Expand Up @@ -39,34 +39,23 @@
# Add helper near top after db & agent init
# -------------- Helper ----------------

_embed_logger = logging.getLogger("embedding_debug")

def _apply_index_embedding_model(idx_ids):
"""Ensure retrieval pipeline uses the embedding model stored with the first index."""
debug_info = f"🔧 _apply_index_embedding_model called with idx_ids: {idx_ids}\n"

if not idx_ids:
debug_info += "⚠️ No index IDs provided\n"
with open("logs/embedding_debug.log", "a") as f:
f.write(debug_info)
_embed_logger.debug("No index IDs provided")
return
try:
idx = db.get_index(idx_ids[0])
debug_info += f"🔧 Retrieved index: {idx.get('id')} with metadata: {idx.get('metadata', {})}\n"
model = (idx.get("metadata") or {}).get("embedding_model")
debug_info += f"🔧 Embedding model from metadata: {model}\n"
_embed_logger.debug("Index %s embedding_model=%s", idx_ids[0], model)
if model:
rp = RAG_AGENT.retrieval_pipeline
current_model = rp.config.get("embedding_model_name")
debug_info += f"🔧 Current embedding model: {current_model}\n"
rp.update_embedding_model(model)
debug_info += f"🔧 Updated embedding model to: {model}\n"
else:
debug_info += "⚠️ No embedding model found in metadata\n"
_embed_logger.debug("Updated embedding model to: %s", model)
except Exception as e:
debug_info += f"⚠️ Could not apply index embedding model: {e}\n"

# Write debug info to file
with open("logs/embedding_debug.log", "a") as f:
f.write(debug_info)
_embed_logger.warning("Could not apply index embedding model: %s", e)

def _get_table_name_for_session(session_id):
"""Get the correct vector table name for a session by looking up its linked indexes."""
Expand Down
Loading