@@ -341,315 +341,6 @@ def construct_payload_configuration(
341341 }
342342
343343
344- class _AzureCosmosDbMongoVcoreSettings (
345- BaseSettings ,
346- DatasourcePayloadConstructor
347- ):
348- model_config = SettingsConfigDict (
349- env_prefix = "AZURE_COSMOSDB_MONGO_VCORE_" ,
350- env_file = DOTENV_PATH ,
351- extra = "ignore" ,
352- env_ignore_empty = True
353- )
354- _type : Literal ["azure_cosmosdb" ] = PrivateAttr (default = "azure_cosmosdb" )
355- top_k : int = Field (default = 5 , serialization_alias = "top_n_documents" )
356- strictness : int = 3
357- enable_in_domain : bool = Field (default = True , serialization_alias = "in_scope" )
358- query_type : Literal ['vector' ] = "vector"
359- connection_string : str = Field (exclude = True )
360- index : str = Field (serialization_alias = "index_name" )
361- database : str = Field (serialization_alias = "database_name" )
362- container : str = Field (serialization_alias = "container_name" )
363- content_columns : Optional [List [str ]] = Field (default = None , exclude = True )
364- vector_columns : Optional [List [str ]] = Field (default = None , exclude = True )
365- title_column : Optional [str ] = Field (default = None , exclude = True )
366- url_column : Optional [str ] = Field (default = None , exclude = True )
367- filename_column : Optional [str ] = Field (default = None , exclude = True )
368-
369- # Constructed fields
370- authentication : Optional [dict ] = None
371- embedding_dependency : Optional [dict ] = None
372- fields_mapping : Optional [dict ] = None
373-
374- @field_validator ('content_columns' , 'vector_columns' , mode = "before" )
375- @classmethod
376- def split_columns (cls , comma_separated_string : str ) -> List [str ]:
377- if isinstance (comma_separated_string , str ) and len (comma_separated_string ) > 0 :
378- return parse_multi_columns (comma_separated_string )
379-
380- return None
381-
382- @model_validator (mode = "after" )
383- def construct_authentication (self ) -> Self :
384- self .authentication = {
385- "type" : "connection_string" ,
386- "connection_string" : self .connection_string
387- }
388- return self
389-
390- @model_validator (mode = "after" )
391- def set_fields_mapping (self ) -> Self :
392- self .fields_mapping = {
393- "content_fields" : self .content_columns ,
394- "title_field" : self .title_column ,
395- "url_field" : self .url_column ,
396- "filepath_field" : self .filename_column ,
397- "vector_fields" : self .vector_columns
398- }
399- return self
400-
401- def construct_payload_configuration (
402- self ,
403- * args ,
404- ** kwargs
405- ):
406- self .embedding_dependency = \
407- self ._settings .azure_openai .extract_embedding_dependency ()
408- parameters = self .model_dump (exclude_none = True , by_alias = True )
409- parameters .update (self ._settings .search .model_dump (exclude_none = True , by_alias = True ))
410- return {
411- "type" : self ._type ,
412- "parameters" : parameters
413- }
414-
415-
416- class _ElasticsearchSettings (BaseSettings , DatasourcePayloadConstructor ):
417- model_config = SettingsConfigDict (
418- env_prefix = "ELASTICSEARCH_" ,
419- env_file = DOTENV_PATH ,
420- extra = "ignore" ,
421- env_ignore_empty = True
422- )
423- _type : Literal ["elasticsearch" ] = PrivateAttr (default = "elasticsearch" )
424- top_k : int = Field (default = 5 , serialization_alias = "top_n_documents" )
425- strictness : int = 3
426- enable_in_domain : bool = Field (default = True , serialization_alias = "in_scope" )
427- endpoint : str
428- encoded_api_key : str = Field (exclude = True )
429- index : str = Field (serialization_alias = "index_name" )
430- query_type : Literal ['simple' , 'vector' ] = "simple"
431- content_columns : Optional [List [str ]] = Field (default = None , exclude = True )
432- vector_columns : Optional [List [str ]] = Field (default = None , exclude = True )
433- title_column : Optional [str ] = Field (default = None , exclude = True )
434- url_column : Optional [str ] = Field (default = None , exclude = True )
435- filename_column : Optional [str ] = Field (default = None , exclude = True )
436- embedding_model_id : Optional [str ] = Field (default = None , exclude = True )
437-
438- # Constructed fields
439- authentication : Optional [dict ] = None
440- embedding_dependency : Optional [dict ] = None
441- fields_mapping : Optional [dict ] = None
442-
443- @field_validator ('content_columns' , 'vector_columns' , mode = "before" )
444- @classmethod
445- def split_columns (cls , comma_separated_string : str ) -> List [str ]:
446- if isinstance (comma_separated_string , str ) and len (comma_separated_string ) > 0 :
447- return parse_multi_columns (comma_separated_string )
448-
449- return None
450-
451- @model_validator (mode = "after" )
452- def set_authentication (self ) -> Self :
453- self .authentication = {
454- "type" : "encoded_api_key" ,
455- "encoded_api_key" : self .encoded_api_key
456- }
457-
458- return self
459-
460- @model_validator (mode = "after" )
461- def set_fields_mapping (self ) -> Self :
462- self .fields_mapping = {
463- "content_fields" : self .content_columns ,
464- "title_field" : self .title_column ,
465- "url_field" : self .url_column ,
466- "filepath_field" : self .filename_column ,
467- "vector_fields" : self .vector_columns
468- }
469- return self
470-
471- def construct_payload_configuration (
472- self ,
473- * args ,
474- ** kwargs
475- ):
476- self .embedding_dependency = \
477- {"type" : "model_id" , "model_id" : self .embedding_model_id } if self .embedding_model_id else \
478- self ._settings .azure_openai .extract_embedding_dependency ()
479-
480- parameters = self .model_dump (exclude_none = True , by_alias = True )
481- parameters .update (self ._settings .search .model_dump (exclude_none = True , by_alias = True ))
482-
483- return {
484- "type" : self ._type ,
485- "parameters" : parameters
486- }
487-
488-
489- class _PineconeSettings (BaseSettings , DatasourcePayloadConstructor ):
490- model_config = SettingsConfigDict (
491- env_prefix = "PINECONE_" ,
492- env_file = DOTENV_PATH ,
493- extra = "ignore" ,
494- env_ignore_empty = True
495- )
496- _type : Literal ["pinecone" ] = PrivateAttr (default = "pinecone" )
497- top_k : int = Field (default = 5 , serialization_alias = "top_n_documents" )
498- strictness : int = 3
499- enable_in_domain : bool = Field (default = True , serialization_alias = "in_scope" )
500- environment : str
501- api_key : str = Field (exclude = True )
502- index_name : str
503- query_type : Literal ["vector" ] = "vector"
504- content_columns : Optional [List [str ]] = Field (default = None , exclude = True )
505- vector_columns : Optional [List [str ]] = Field (default = None , exclude = True )
506- title_column : Optional [str ] = Field (default = None , exclude = True )
507- url_column : Optional [str ] = Field (default = None , exclude = True )
508- filename_column : Optional [str ] = Field (default = None , exclude = True )
509-
510- # Constructed fields
511- authentication : Optional [dict ] = None
512- embedding_dependency : Optional [dict ] = None
513- fields_mapping : Optional [dict ] = None
514-
515- @field_validator ('content_columns' , 'vector_columns' , mode = "before" )
516- @classmethod
517- def split_columns (cls , comma_separated_string : str ) -> List [str ]:
518- if isinstance (comma_separated_string , str ) and len (comma_separated_string ) > 0 :
519- return parse_multi_columns (comma_separated_string )
520-
521- return None
522-
523- @model_validator (mode = "after" )
524- def set_authentication (self ) -> Self :
525- self .authentication = {
526- "type" : "api_key" ,
527- "api_key" : self .api_key
528- }
529-
530- return self
531-
532- @model_validator (mode = "after" )
533- def set_fields_mapping (self ) -> Self :
534- self .fields_mapping = {
535- "content_fields" : self .content_columns ,
536- "title_field" : self .title_column ,
537- "url_field" : self .url_column ,
538- "filepath_field" : self .filename_column ,
539- "vector_fields" : self .vector_columns
540- }
541- return self
542-
543- def construct_payload_configuration (
544- self ,
545- * args ,
546- ** kwargs
547- ):
548- self .embedding_dependency = \
549- self ._settings .azure_openai .extract_embedding_dependency ()
550- parameters = self .model_dump (exclude_none = True , by_alias = True )
551- parameters .update (self ._settings .search .model_dump (exclude_none = True , by_alias = True ))
552-
553- return {
554- "type" : self ._type ,
555- "parameters" : parameters
556- }
557-
558-
559- class _AzureMLIndexSettings (BaseSettings , DatasourcePayloadConstructor ):
560- model_config = SettingsConfigDict (
561- env_prefix = "AZURE_MLINDEX_" ,
562- env_file = DOTENV_PATH ,
563- extra = "ignore" ,
564- env_ignore_empty = True
565- )
566- _type : Literal ["azure_ml_index" ] = PrivateAttr (default = "azure_ml_index" )
567- top_k : int = Field (default = 5 , serialization_alias = "top_n_documents" )
568- strictness : int = 3
569- enable_in_domain : bool = Field (default = True , serialization_alias = "in_scope" )
570- name : str
571- version : str
572- project_resource_id : str = Field (validation_alias = "AZURE_ML_PROJECT_RESOURCE_ID" )
573- content_columns : Optional [List [str ]] = Field (default = None , exclude = True )
574- vector_columns : Optional [List [str ]] = Field (default = None , exclude = True )
575- title_column : Optional [str ] = Field (default = None , exclude = True )
576- url_column : Optional [str ] = Field (default = None , exclude = True )
577- filename_column : Optional [str ] = Field (default = None , exclude = True )
578-
579- # Constructed fields
580- fields_mapping : Optional [dict ] = None
581-
582- @field_validator ('content_columns' , 'vector_columns' , mode = "before" )
583- @classmethod
584- def split_columns (cls , comma_separated_string : str ) -> List [str ]:
585- if isinstance (comma_separated_string , str ) and len (comma_separated_string ) > 0 :
586- return parse_multi_columns (comma_separated_string )
587-
588- return None
589-
590- @model_validator (mode = "after" )
591- def set_fields_mapping (self ) -> Self :
592- self .fields_mapping = {
593- "content_fields" : self .content_columns ,
594- "title_field" : self .title_column ,
595- "url_field" : self .url_column ,
596- "filepath_field" : self .filename_column ,
597- "vector_fields" : self .vector_columns
598- }
599- return self
600-
601- def construct_payload_configuration (
602- self ,
603- * args ,
604- ** kwargs
605- ):
606- parameters = self .model_dump (exclude_none = True , by_alias = True )
607- parameters .update (self ._settings .search .model_dump (exclude_none = True , by_alias = True ))
608-
609- return {
610- "type" : self ._type ,
611- "parameters" : parameters
612- }
613-
614-
615- class _AzureSqlServerSettings (BaseSettings , DatasourcePayloadConstructor ):
616- model_config = SettingsConfigDict (
617- env_prefix = "AZURE_SQL_SERVER_" ,
618- env_file = DOTENV_PATH ,
619- extra = "ignore"
620- )
621- _type : Literal ["azure_sql_server" ] = PrivateAttr (default = "azure_sql_server" )
622-
623- connection_string : str = Field (exclude = True )
624- table_schema : str
625- schema_max_row : Optional [int ] = None
626- top_n_results : Optional [int ] = None
627-
628- # Constructed fields
629- authentication : Optional [dict ] = None
630-
631- @model_validator (mode = "after" )
632- def construct_authentication (self ) -> Self :
633- self .authentication = {
634- "type" : "connection_string" ,
635- "connection_string" : self .connection_string
636- }
637- return self
638-
639- def construct_payload_configuration (
640- self ,
641- * args ,
642- ** kwargs
643- ):
644- parameters = self .model_dump (exclude_none = True , by_alias = True )
645- #parameters.update(self._settings.search.model_dump(exclude_none=True, by_alias=True))
646-
647- return {
648- "type" : self ._type ,
649- "parameters" : parameters
650- }
651-
652-
653344class _BaseSettings (BaseSettings ):
654345 model_config = SettingsConfigDict (
655346 env_file = DOTENV_PATH ,
@@ -700,27 +391,6 @@ def set_datasource_settings(self) -> Self:
700391 if self .base_settings .datasource_type == "AzureCognitiveSearch" :
701392 self .datasource = _AzureSearchSettings (settings = self , _env_file = DOTENV_PATH )
702393 logging .debug ("Using Azure Cognitive Search" )
703-
704- elif self .base_settings .datasource_type == "AzureCosmosDB" :
705- self .datasource = _AzureCosmosDbMongoVcoreSettings (settings = self , _env_file = DOTENV_PATH )
706- logging .debug ("Using Azure CosmosDB Mongo vcore" )
707-
708- elif self .base_settings .datasource_type == "Elasticsearch" :
709- self .datasource = _ElasticsearchSettings (settings = self , _env_file = DOTENV_PATH )
710- logging .debug ("Using Elasticsearch" )
711-
712- elif self .base_settings .datasource_type == "Pinecone" :
713- self .datasource = _PineconeSettings (settings = self , _env_file = DOTENV_PATH )
714- logging .debug ("Using Pinecone" )
715-
716- elif self .base_settings .datasource_type == "AzureMLIndex" :
717- self .datasource = _AzureMLIndexSettings (settings = self , _env_file = DOTENV_PATH )
718- logging .debug ("Using Azure ML Index" )
719-
720- elif self .base_settings .datasource_type == "AzureSqlServer" :
721- self .datasource = _AzureSqlServerSettings (settings = self , _env_file = DOTENV_PATH )
722- logging .debug ("Using SQL Server" )
723-
724394 else :
725395 self .datasource = None
726396 logging .warning ("No datasource configuration found in the environment -- calls will be made to Azure OpenAI without grounding data." )
0 commit comments