22from controller .tokenization .tokenization_service import (
33 request_reupload_docbins ,
44)
5+ import json
56from submodules .model .business_objects import (
67 attribute ,
78 record ,
89 tokenization ,
910 general ,
1011)
1112from submodules .model .models import Attribute
12- from submodules .model .enums import AttributeState , DataTypes , RecordTokenizationScope
13+ from submodules .model .enums import (
14+ AttributeState ,
15+ DataTypes ,
16+ RecordTokenizationScope ,
17+ AttributeVisibility ,
18+ )
1319from util import daemon , notification
1420
1521from controller .task_queue import manager as task_queue_manager
@@ -68,6 +74,9 @@ def create_user_attribute(project_id: str, name: str, data_type: str) -> Attribu
6874 relative_position = 1
6975 else :
7076 relative_position = prev_relative_position + 1
77+ visibility = None # default
78+ if data_type == DataTypes .EMBEDDING_LIST .value :
79+ visibility = AttributeVisibility .HIDE .value
7180
7281 attribute_item : Attribute = attribute .create (
7382 project_id ,
@@ -77,6 +86,7 @@ def create_user_attribute(project_id: str, name: str, data_type: str) -> Attribu
7786 is_primary_key = False ,
7887 user_created = True ,
7988 state = AttributeState .INITIAL .value ,
89+ visibility = visibility ,
8090 with_commit = True ,
8191 )
8292 notification .send_organization_update (
@@ -355,4 +365,15 @@ def calculate_user_attribute_sample_records(
355365 calculated_attributes = util .run_attribute_calculation_exec_env (
356366 attribute_id = attribute_id , project_id = project_id , doc_bin = doc_bin_samples
357367 )
358- return list (calculated_attributes .keys ()), list (calculated_attributes .values ())
368+ values = None
369+ if (
370+ attribute .get (project_id , attribute_id ).data_type
371+ == DataTypes .EMBEDDING_LIST .value
372+ ):
373+ # values are json serialized so they can be easily transferred to the frontend.
374+ # Since the return type is a list of strings, without json.dumps a str(xxxx) will be called
375+ # which can't be easily deserialized if special characters are in the string
376+ values = [json .dumps (v ) for v in list (calculated_attributes .values ())]
377+ else :
378+ values = list (calculated_attributes .values ())
379+ return list (calculated_attributes .keys ()), values
0 commit comments