Skip to content

Commit d27b96e

Browse files
committed
feat: Terminology / SQL Sample Management add enabled control
1 parent 0ba2655 commit d27b96e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

backend/apps/data_training/curd/data_training.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def page_data_training(session: SessionDep, current_page: int = 1, page_size: in
6262
DataTraining.question,
6363
DataTraining.create_time,
6464
DataTraining.description,
65+
DataTraining.enabled,
6566
)
6667
.outerjoin(CoreDatasource, and_(DataTraining.datasource == CoreDatasource.id))
6768
.where(and_(DataTraining.id.in_(paginated_parent_ids)))
@@ -79,6 +80,7 @@ def page_data_training(session: SessionDep, current_page: int = 1, page_size: in
7980
question=row.question,
8081
create_time=row.create_time,
8182
description=row.description,
83+
enabled=row.enabled,
8284
))
8385

8486
return current_page, page_size, total_count, total_pages, _list
@@ -221,11 +223,11 @@ def save_embeddings(session_maker, ids: List[int]):
221223
embedding_sql = f"""
222224
SELECT id, datasource, question, similarity
223225
FROM
224-
(SELECT id, datasource, question, oid,
226+
(SELECT id, datasource, question, oid, enabled,
225227
( 1 - (embedding <=> :embedding_array) ) AS similarity
226228
FROM data_training AS child
227229
) TEMP
228-
WHERE similarity > {settings.EMBEDDING_DATA_TRAINING_SIMILARITY} and oid = :oid and datasource = :datasource
230+
WHERE similarity > {settings.EMBEDDING_DATA_TRAINING_SIMILARITY} and oid = :oid and datasource = :datasource and enabled = true
229231
ORDER BY similarity DESC
230232
LIMIT {settings.EMBEDDING_DATA_TRAINING_TOP_COUNT}
231233
"""
@@ -246,7 +248,8 @@ def select_training_by_question(session: SessionDep, question: str, oid: int, da
246248
.where(
247249
and_(or_(text(":sentence ILIKE '%' || question || '%'"), text("question ILIKE '%' || :sentence || '%'")),
248250
DataTraining.oid == oid,
249-
DataTraining.datasource == datasource)
251+
DataTraining.datasource == datasource,
252+
DataTraining.enabled == True,)
250253
)
251254
)
252255

backend/apps/terminology/curd/terminology.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
9999
Terminology.specific_ds,
100100
Terminology.datasource_ids,
101101
children_subquery.c.other_words,
102-
func.jsonb_agg(CoreDatasource.name).filter(CoreDatasource.id.isnot(None)).label('datasource_names')
102+
func.jsonb_agg(CoreDatasource.name).filter(CoreDatasource.id.isnot(None)).label('datasource_names'),
103+
Terminology.enabled
103104
)
104105
.outerjoin(
105106
children_subquery,
@@ -122,7 +123,8 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
122123
Terminology.description,
123124
Terminology.specific_ds,
124125
Terminology.datasource_ids,
125-
children_subquery.c.other_words
126+
children_subquery.c.other_words,
127+
Terminology.enabled
126128
)
127129
.order_by(Terminology.create_time.desc())
128130
)
@@ -175,7 +177,8 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
175177
Terminology.specific_ds,
176178
Terminology.datasource_ids,
177179
children_subquery.c.other_words,
178-
func.jsonb_agg(CoreDatasource.name).filter(CoreDatasource.id.isnot(None)).label('datasource_names')
180+
func.jsonb_agg(CoreDatasource.name).filter(CoreDatasource.id.isnot(None)).label('datasource_names'),
181+
Terminology.enabled
179182
)
180183
.outerjoin(
181184
children_subquery,
@@ -197,7 +200,8 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
197200
Terminology.description,
198201
Terminology.specific_ds,
199202
Terminology.datasource_ids,
200-
children_subquery.c.other_words
203+
children_subquery.c.other_words,
204+
Terminology.enabled
201205
)
202206
.order_by(Terminology.create_time.desc())
203207
)
@@ -214,6 +218,7 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
214218
specific_ds=row.specific_ds if row.specific_ds is not None else False,
215219
datasource_ids=row.datasource_ids if row.datasource_ids is not None else [],
216220
datasource_names=row.datasource_names if row.datasource_names is not None else [],
221+
enabled=row.enabled if row.enabled is not None else False,
217222
))
218223

219224
return current_page, page_size, total_count, total_pages, _list
@@ -474,11 +479,11 @@ def save_embeddings(session_maker, ids: List[int]):
474479
embedding_sql = f"""
475480
SELECT id, pid, word, similarity
476481
FROM
477-
(SELECT id, pid, word, oid, specific_ds, datasource_ids,
482+
(SELECT id, pid, word, oid, specific_ds, datasource_ids, enabled,
478483
( 1 - (embedding <=> :embedding_array) ) AS similarity
479484
FROM terminology AS child
480485
) TEMP
481-
WHERE similarity > {settings.EMBEDDING_TERMINOLOGY_SIMILARITY} AND oid = :oid
486+
WHERE similarity > {settings.EMBEDDING_TERMINOLOGY_SIMILARITY} AND oid = :oid AND enabled = true
482487
AND (specific_ds = false OR specific_ds IS NULL)
483488
ORDER BY similarity DESC
484489
LIMIT {settings.EMBEDDING_TERMINOLOGY_TOP_COUNT}
@@ -487,11 +492,11 @@ def save_embeddings(session_maker, ids: List[int]):
487492
embedding_sql_with_datasource = f"""
488493
SELECT id, pid, word, similarity
489494
FROM
490-
(SELECT id, pid, word, oid, specific_ds, datasource_ids,
495+
(SELECT id, pid, word, oid, specific_ds, datasource_ids, enabled,
491496
( 1 - (embedding <=> :embedding_array) ) AS similarity
492497
FROM terminology AS child
493498
) TEMP
494-
WHERE similarity > {settings.EMBEDDING_TERMINOLOGY_SIMILARITY} AND oid = :oid
499+
WHERE similarity > {settings.EMBEDDING_TERMINOLOGY_SIMILARITY} AND oid = :oid AND enabled = true
495500
AND (
496501
(specific_ds = false OR specific_ds IS NULL)
497502
OR
@@ -515,7 +520,7 @@ def select_terminology_by_word(session: SessionDep, word: str, oid: int, datasou
515520
Terminology.word,
516521
)
517522
.where(
518-
and_(text(":sentence ILIKE '%' || word || '%'"), Terminology.oid == oid)
523+
and_(text(":sentence ILIKE '%' || word || '%'"), Terminology.oid == oid, Terminology.enabled == True)
519524
)
520525
)
521526

0 commit comments

Comments
 (0)