MCPcopy
hub / github.com/PromtEngineer/localGPT / _get_table_name_for_session

Function _get_table_name_for_session

rag_system/api_server.py:71–113  ·  view source on GitHub ↗

Get the correct vector table name for a session by looking up its linked indexes.

(session_id)

Source from the content-addressed store, hash-verified

69 f.write(debug_info)
70
71def _get_table_name_for_session(session_id):
72 """Get the correct vector table name for a session by looking up its linked indexes."""
73 logger = logging.getLogger(__name__)
74
75 if not session_id:
76 logger.info("❌ No session_id provided")
77 return None
78
79 try:
80 # Get indexes linked to this session
81 idx_ids = db.get_indexes_for_session(session_id)
82 logger.info(f"🔍 Session {session_id[:8]}... has {len(idx_ids)} indexes: {idx_ids}")
83
84 if not idx_ids:
85 logger.warning(f"⚠️ No indexes found for session {session_id}")
86 # Use the default table name from config instead of session-specific name
87 from rag_system.main import PIPELINE_CONFIGS
88 default_table = PIPELINE_CONFIGS["default"]["storage"]["text_table_name"]
89 logger.info(f"📊 Using default table '{default_table}' for session {session_id[:8]}...")
90 return default_table
91
92 # Use the first index's vector table name
93 idx = db.get_index(idx_ids[0])
94 if idx and idx.get('vector_table_name'):
95 table_name = idx['vector_table_name']
96 logger.info(f"📊 Using table '{table_name}' for session {session_id[:8]}...")
97 print(f"📊 RAG API: Using table '{table_name}' for session {session_id[:8]}...")
98 return table_name
99 else:
100 logger.warning(f"⚠️ Index found but no vector table name for session {session_id}")
101 # Use the default table name from config instead of session-specific name
102 from rag_system.main import PIPELINE_CONFIGS
103 default_table = PIPELINE_CONFIGS["default"]["storage"]["text_table_name"]
104 logger.info(f"📊 Using default table '{default_table}' for session {session_id[:8]}...")
105 return default_table
106
107 except Exception as e:
108 logger.error(f"❌ Error getting table name for session {session_id}: {e}")
109 # Use the default table name from config instead of session-specific name
110 from rag_system.main import PIPELINE_CONFIGS
111 default_table = PIPELINE_CONFIGS["default"]["storage"]["text_table_name"]
112 logger.info(f"📊 Using default table '{default_table}' for session {session_id[:8]}...")
113 return default_table
114
115class AdvancedRagApiHandler(http.server.BaseHTTPRequestHandler):
116 def do_OPTIONS(self):

Callers 3

handle_chatMethod · 0.85
handle_chat_streamMethod · 0.85
handle_indexMethod · 0.85

Calls 2

get_indexMethod · 0.80

Tested by

no test coverage detected