@@ -384,48 +384,6 @@ async def get_documents_by_id(
384384 logger .error (f"Error batch retrieving documents: { str (e )} " )
385385 return []
386386
387- async def get_documents (
388- self ,
389- auth : AuthContext ,
390- skip : int = 0 ,
391- limit : int = 10000 ,
392- filters : Optional [Dict [str , Any ]] = None ,
393- system_filters : Optional [Dict [str , Any ]] = None ,
394- ) -> List [Document ]:
395- """List documents the user has access to."""
396- try :
397- async with self .async_session () as session :
398- # Build query
399- access_filter = self ._build_access_filter_optimized (auth )
400- metadata_filter = self ._build_metadata_filter (filters )
401- system_metadata_filter = self ._build_system_metadata_filter_optimized (system_filters )
402- filter_params = self ._build_filter_params (auth , system_filters )
403-
404- where_clauses = [f"({ access_filter } )" ]
405-
406- if metadata_filter :
407- where_clauses .append (f"({ metadata_filter } )" )
408-
409- if system_metadata_filter :
410- where_clauses .append (f"({ system_metadata_filter } )" )
411-
412- final_where_clause = " AND " .join (where_clauses )
413- query = select (DocumentModel ).where (text (final_where_clause ).bindparams (** filter_params ))
414-
415- query = query .offset (skip ).limit (limit )
416-
417- result = await session .execute (query )
418- doc_models = result .scalars ().all ()
419-
420- return [Document (** _document_model_to_dict (doc )) for doc in doc_models ]
421-
422- except InvalidMetadataFilterError as exc :
423- logger .warning ("Invalid metadata filter while listing documents: %s" , exc )
424- raise
425- except Exception as e :
426- logger .error (f"Error listing documents: { str (e )} " )
427- return []
428-
429387 async def list_documents_flexible (
430388 self ,
431389 auth : AuthContext ,
@@ -2013,34 +1971,6 @@ async def store_model_config(self, model_config: ModelConfig) -> bool:
20131971 logger .error (f"Error storing model config: { str (e )} " )
20141972 return False
20151973
2016- async def get_model_config (self , config_id : str , user_id : str , app_id : str ) -> Optional [ModelConfig ]:
2017- """Get a model configuration by ID if user has access."""
2018- try :
2019- async with self .async_session () as session :
2020- result = await session .execute (
2021- select (ModelConfigModel )
2022- .where (ModelConfigModel .id == config_id )
2023- .where (ModelConfigModel .user_id == user_id )
2024- .where (ModelConfigModel .app_id == app_id )
2025- )
2026- config_model = result .scalar_one_or_none ()
2027-
2028- if config_model :
2029- return ModelConfig (
2030- id = config_model .id ,
2031- user_id = config_model .user_id ,
2032- app_id = config_model .app_id ,
2033- provider = config_model .provider ,
2034- config_data = config_model .config_data ,
2035- created_at = config_model .created_at ,
2036- updated_at = config_model .updated_at ,
2037- )
2038- return None
2039-
2040- except Exception as e :
2041- logger .error (f"Error getting model config: { str (e )} " )
2042- return None
2043-
20441974 async def get_model_configs (self , user_id : str , app_id : str ) -> List [ModelConfig ]:
20451975 """Get all model configurations for a user and app."""
20461976 try :
@@ -2429,62 +2359,6 @@ async def set_document_raw_bytes(self, document_id: str, app_id: Optional[str],
24292359 },
24302360 )
24312361
2432- async def delete_document_storage_usage (self , document_id : str ) -> None :
2433- if not document_id :
2434- logger .warning ("delete_document_storage_usage called with empty document_id" )
2435- return
2436-
2437- async with self .async_session () as session :
2438- async with session .begin ():
2439- result = await session .execute (
2440- text (
2441- """
2442- SELECT app_id, raw_bytes, chunk_bytes, multivector_bytes
2443- FROM document_storage_usage
2444- WHERE document_id = :document_id
2445- """
2446- ),
2447- {"document_id" : document_id },
2448- )
2449- row = result .first ()
2450- if not row :
2451- return
2452-
2453- normalized_app_id = normalize_app_id (row .app_id )
2454- raw_bytes = int (row .raw_bytes or 0 )
2455- chunk_bytes = int (row .chunk_bytes or 0 )
2456- multivector_bytes = int (row .multivector_bytes or 0 )
2457- now = datetime .now (UTC )
2458-
2459- await session .execute (
2460- text ("DELETE FROM document_storage_usage WHERE document_id = :document_id" ),
2461- {"document_id" : document_id },
2462- )
2463-
2464- await session .execute (
2465- text (
2466- """
2467- INSERT INTO app_storage_usage
2468- (app_id, raw_bytes, chunk_bytes, multivector_bytes, created_at, updated_at)
2469- VALUES
2470- (:app_id, 0, 0, 0, :now, :now)
2471- ON CONFLICT (app_id)
2472- DO UPDATE SET
2473- raw_bytes = GREATEST(app_storage_usage.raw_bytes - :raw_bytes, 0),
2474- chunk_bytes = GREATEST(app_storage_usage.chunk_bytes - :chunk_bytes, 0),
2475- multivector_bytes = GREATEST(app_storage_usage.multivector_bytes - :multivector_bytes, 0),
2476- updated_at = :now
2477- """
2478- ),
2479- {
2480- "app_id" : normalized_app_id ,
2481- "raw_bytes" : raw_bytes ,
2482- "chunk_bytes" : chunk_bytes ,
2483- "multivector_bytes" : multivector_bytes ,
2484- "now" : now ,
2485- },
2486- )
2487-
24882362 async def get_app_storage_usage (self , app_id : str ) -> Dict [str , Any ]:
24892363 if not app_id :
24902364 return {"app_id" : normalize_app_id (app_id ), "raw_bytes" : 0 , "chunk_bytes" : 0 , "multivector_bytes" : 0 }
0 commit comments