weave-typescript 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +13 -14
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +62 -74
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +82 -50
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +708 -216
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +50 -7
- package/dist/weaveapi/ingestion/v1/service.pb.js +279 -16
- package/dist/weaveapi/ingestion/v1/table.pb.d.ts +121 -0
- package/dist/weaveapi/ingestion/v1/table.pb.js +1478 -0
- package/dist/weaveapi/model/v1/model.pb.d.ts +3 -3
- package/dist/weaveapi/model/v1/model.pb.js +33 -33
- package/dist/weaveapi/model/v1/service.pb.d.ts +3 -3
- package/dist/weaveapi/model/v1/service.pb.js +33 -33
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +123 -0
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +2096 -113
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +29 -1
- package/dist/weaveapi/retrieval/v1/service.pb.js +142 -0
- package/dist/weavesql/weavedb/consolidation_sql.d.ts +33 -33
- package/dist/weavesql/weavedb/consolidation_sql.js +56 -56
- package/dist/weavesql/weavedb/document_table_sql.d.ts +533 -0
- package/dist/weavesql/weavedb/document_table_sql.js +1352 -0
- package/dist/weavesql/weavedb/ingestion_sql.d.ts +67 -34
- package/dist/weavesql/weavedb/ingestion_sql.js +169 -73
- package/dist/weavesql/weavedb/retrieval_sql.d.ts +11 -11
- package/dist/weavesql/weavedb/retrieval_sql.js +13 -13
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.deactivateFacetConfigQuery = exports.upsertFacetConfigQuery = exports.listActiveFacetConfigsQuery = exports.listFacetConfigsQuery = exports.deleteThreadFacetsByThreadQuery = exports.upsertThreadFacetQuery = exports.listThreadFacetsByThreadIDsQuery = exports.syncOrganizationIngestionReasoningDefaultsQuery = exports.upsertOrganizationIngestionStageSettingsQuery = exports.upsertOrganizationIngestionSettingsQuery = exports.getOrganizationIngestionSettingsQuery = exports.ensureOrganizationIngestionSettingsQuery = void 0;
|
|
3
|
+
exports.upsertEntityRelationshipQuery = exports.upsertThreadEntityQuery = exports.upsertEntityQuery = exports.listThreadActivityByThreadQuery = exports.createThreadActivityQuery = exports.listThreadReconciliationByPendingThreadQuery = exports.upsertThreadReconciliationQuery = exports.deleteThreadReconciliationByPendingThreadQuery = exports.getIngestionRunThreadCountsQuery = exports.listThreadsByIDsQuery = exports.listThreadsBySupersedesQuery = exports.markThreadsSupersededQuery = exports.bulkRejectThreadsQuery = exports.rejectThreadQuery = exports.bulkApproveThreadsQuery = exports.approveThreadQuery = exports.deleteDocumentThreadByOrganizationAndIDQuery = exports.editDocumentThreadQuery = exports.editPendingThreadQuery = exports.updateThreadClassificationQuery = exports.promoteThreadNextEmbeddingsByOrganizationQuery = exports.setThreadNextEmbeddingQuery = exports.updateThreadEmbeddingQuery = exports.listPendingThreadsByOrganizationQuery = exports.listPendingThreadsByRunQuery = exports.listAccessibleThreadsByDocumentQuery = exports.listThreadsByDocumentQuery = exports.listThreadsByIngestionRunQuery = exports.getThreadByOrganizationAndIDQuery = exports.createThreadQuery = exports.deleteDocumentByOrganizationAndIDQuery = exports.listDocumentTagsByDocumentIDQuery = exports.createDocumentTagQuery = exports.deleteDocumentTagByDocumentIDAndTagQuery = exports.deleteDocumentTagsByDocumentIDQuery = exports.listIngestionHistoryQuery = exports.listIngestionRunsByDocumentQuery = exports.listIngestionRunsByOrganizationQuery = exports.updateIngestionRunStateQuery = exports.getIngestionRunByOrganizationAndIDQuery = exports.createIngestionRunQuery = exports.getDatabaseConfigQuery = exports.getAccessibleDocumentSummaryQuery = exports.listAccessibleDocumentSummariesQuery = exports.listDocumentsByOrganizationQuery = exports.setDocumentStatusQuery = exports.setDocumentParseResultQuery = exports.getDocumentByOrganizationAndFingerprintQuery = exports.getDocumentByOrganizationAndIDQuery = exports.createDocumentQuery = void 0;
|
|
4
|
+
exports.deactivateFacetConfigQuery = exports.upsertFacetConfigQuery = exports.listActiveFacetConfigsQuery = exports.listFacetConfigsQuery = exports.deleteThreadFacetsByThreadQuery = exports.upsertThreadFacetQuery = exports.listThreadFacetsByThreadIDsQuery = exports.syncOrganizationIngestionReasoningDefaultsQuery = exports.upsertOrganizationIngestionStageSettingsQuery = exports.upsertOrganizationIngestionSettingsQuery = exports.getOrganizationIngestionSettingsQuery = exports.ensureOrganizationIngestionSettingsQuery = exports.listEntitiesByThreadQuery = void 0;
|
|
5
5
|
exports.createDocument = createDocument;
|
|
6
6
|
exports.getDocumentByOrganizationAndID = getDocumentByOrganizationAndID;
|
|
7
7
|
exports.getDocumentByOrganizationAndFingerprint = getDocumentByOrganizationAndFingerprint;
|
|
@@ -24,6 +24,7 @@ exports.createThread = createThread;
|
|
|
24
24
|
exports.getThreadByOrganizationAndID = getThreadByOrganizationAndID;
|
|
25
25
|
exports.listThreadsByIngestionRun = listThreadsByIngestionRun;
|
|
26
26
|
exports.listThreadsByDocument = listThreadsByDocument;
|
|
27
|
+
exports.listAccessibleThreadsByDocument = listAccessibleThreadsByDocument;
|
|
27
28
|
exports.listPendingThreadsByRun = listPendingThreadsByRun;
|
|
28
29
|
exports.listPendingThreadsByOrganization = listPendingThreadsByOrganization;
|
|
29
30
|
exports.updateThreadEmbedding = updateThreadEmbedding;
|
|
@@ -689,7 +690,7 @@ INSERT INTO weave.ingestion_runs (
|
|
|
689
690
|
embedding_provider_configuration_id,
|
|
690
691
|
embedding_dimensions,
|
|
691
692
|
stage_model_settings,
|
|
692
|
-
|
|
693
|
+
create_thread_loop_count
|
|
693
694
|
) VALUES (
|
|
694
695
|
$1,
|
|
695
696
|
$2,
|
|
@@ -714,7 +715,7 @@ RETURNING
|
|
|
714
715
|
embedding_provider_configuration_id,
|
|
715
716
|
embedding_dimensions,
|
|
716
717
|
stage_model_settings,
|
|
717
|
-
|
|
718
|
+
create_thread_loop_count,
|
|
718
719
|
thread_count,
|
|
719
720
|
pending_count,
|
|
720
721
|
approved_count,
|
|
@@ -727,7 +728,7 @@ RETURNING
|
|
|
727
728
|
async function createIngestionRun(client, args) {
|
|
728
729
|
const result = await client.query({
|
|
729
730
|
text: exports.createIngestionRunQuery,
|
|
730
|
-
values: [args.id, args.organizationId, args.documentId, args.status, args.reasoningModelId, args.reasoningProviderConfigurationId, args.embeddingModelId, args.embeddingProviderConfigurationId, args.embeddingDimensions, args.stageModelSettings, args.
|
|
731
|
+
values: [args.id, args.organizationId, args.documentId, args.status, args.reasoningModelId, args.reasoningProviderConfigurationId, args.embeddingModelId, args.embeddingProviderConfigurationId, args.embeddingDimensions, args.stageModelSettings, args.createThreadLoopCount],
|
|
731
732
|
rowMode: "array"
|
|
732
733
|
});
|
|
733
734
|
if (result.rows.length !== 1) {
|
|
@@ -745,7 +746,7 @@ async function createIngestionRun(client, args) {
|
|
|
745
746
|
embeddingProviderConfigurationId: row[7],
|
|
746
747
|
embeddingDimensions: row[8],
|
|
747
748
|
stageModelSettings: row[9],
|
|
748
|
-
|
|
749
|
+
createThreadLoopCount: row[10],
|
|
749
750
|
threadCount: row[11],
|
|
750
751
|
pendingCount: row[12],
|
|
751
752
|
approvedCount: row[13],
|
|
@@ -769,7 +770,7 @@ SELECT
|
|
|
769
770
|
embedding_provider_configuration_id,
|
|
770
771
|
embedding_dimensions,
|
|
771
772
|
stage_model_settings,
|
|
772
|
-
|
|
773
|
+
create_thread_loop_count,
|
|
773
774
|
thread_count,
|
|
774
775
|
pending_count,
|
|
775
776
|
approved_count,
|
|
@@ -803,7 +804,7 @@ async function getIngestionRunByOrganizationAndID(client, args) {
|
|
|
803
804
|
embeddingProviderConfigurationId: row[7],
|
|
804
805
|
embeddingDimensions: row[8],
|
|
805
806
|
stageModelSettings: row[9],
|
|
806
|
-
|
|
807
|
+
createThreadLoopCount: row[10],
|
|
807
808
|
threadCount: row[11],
|
|
808
809
|
pendingCount: row[12],
|
|
809
810
|
approvedCount: row[13],
|
|
@@ -840,7 +841,7 @@ RETURNING
|
|
|
840
841
|
embedding_provider_configuration_id,
|
|
841
842
|
embedding_dimensions,
|
|
842
843
|
stage_model_settings,
|
|
843
|
-
|
|
844
|
+
create_thread_loop_count,
|
|
844
845
|
thread_count,
|
|
845
846
|
pending_count,
|
|
846
847
|
approved_count,
|
|
@@ -871,7 +872,7 @@ async function updateIngestionRunState(client, args) {
|
|
|
871
872
|
embeddingProviderConfigurationId: row[7],
|
|
872
873
|
embeddingDimensions: row[8],
|
|
873
874
|
stageModelSettings: row[9],
|
|
874
|
-
|
|
875
|
+
createThreadLoopCount: row[10],
|
|
875
876
|
threadCount: row[11],
|
|
876
877
|
pendingCount: row[12],
|
|
877
878
|
approvedCount: row[13],
|
|
@@ -895,7 +896,7 @@ SELECT
|
|
|
895
896
|
embedding_provider_configuration_id,
|
|
896
897
|
embedding_dimensions,
|
|
897
898
|
stage_model_settings,
|
|
898
|
-
|
|
899
|
+
create_thread_loop_count,
|
|
899
900
|
thread_count,
|
|
900
901
|
pending_count,
|
|
901
902
|
approved_count,
|
|
@@ -927,7 +928,7 @@ async function listIngestionRunsByOrganization(client, args) {
|
|
|
927
928
|
embeddingProviderConfigurationId: row[7],
|
|
928
929
|
embeddingDimensions: row[8],
|
|
929
930
|
stageModelSettings: row[9],
|
|
930
|
-
|
|
931
|
+
createThreadLoopCount: row[10],
|
|
931
932
|
threadCount: row[11],
|
|
932
933
|
pendingCount: row[12],
|
|
933
934
|
approvedCount: row[13],
|
|
@@ -952,7 +953,7 @@ SELECT
|
|
|
952
953
|
embedding_provider_configuration_id,
|
|
953
954
|
embedding_dimensions,
|
|
954
955
|
stage_model_settings,
|
|
955
|
-
|
|
956
|
+
create_thread_loop_count,
|
|
956
957
|
thread_count,
|
|
957
958
|
pending_count,
|
|
958
959
|
approved_count,
|
|
@@ -984,7 +985,7 @@ async function listIngestionRunsByDocument(client, args) {
|
|
|
984
985
|
embeddingProviderConfigurationId: row[7],
|
|
985
986
|
embeddingDimensions: row[8],
|
|
986
987
|
stageModelSettings: row[9],
|
|
987
|
-
|
|
988
|
+
createThreadLoopCount: row[10],
|
|
988
989
|
threadCount: row[11],
|
|
989
990
|
pendingCount: row[12],
|
|
990
991
|
approvedCount: row[13],
|
|
@@ -1386,6 +1387,101 @@ async function listThreadsByDocument(client, args) {
|
|
|
1386
1387
|
};
|
|
1387
1388
|
});
|
|
1388
1389
|
}
|
|
1390
|
+
exports.listAccessibleThreadsByDocumentQuery = `-- name: ListAccessibleThreadsByDocument :many
|
|
1391
|
+
SELECT
|
|
1392
|
+
t.id,
|
|
1393
|
+
t.organization_id,
|
|
1394
|
+
t.document_id,
|
|
1395
|
+
d.filename AS document_name,
|
|
1396
|
+
t.ingestion_run_id,
|
|
1397
|
+
t.text,
|
|
1398
|
+
t.text_original,
|
|
1399
|
+
t.knowledge_type,
|
|
1400
|
+
t.facet_fields,
|
|
1401
|
+
t.confidence,
|
|
1402
|
+
t.temporal_validity,
|
|
1403
|
+
t.classification,
|
|
1404
|
+
t.retrieval_status,
|
|
1405
|
+
t.source_location,
|
|
1406
|
+
t.superseded_by,
|
|
1407
|
+
t.supersedes,
|
|
1408
|
+
t.cluster_id,
|
|
1409
|
+
t.extracted_at,
|
|
1410
|
+
t.approved_at,
|
|
1411
|
+
t.approved_by_user_id,
|
|
1412
|
+
t.edited,
|
|
1413
|
+
t.metadata
|
|
1414
|
+
FROM weave.threads t
|
|
1415
|
+
JOIN weave.documents d
|
|
1416
|
+
ON d.organization_id = t.organization_id
|
|
1417
|
+
AND d.id = t.document_id
|
|
1418
|
+
WHERE t.organization_id = $1
|
|
1419
|
+
AND t.document_id = $2
|
|
1420
|
+
AND (
|
|
1421
|
+
d.scope = 'DOCUMENT_SCOPE_ORG'
|
|
1422
|
+
OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'
|
|
1423
|
+
AND d.uploaded_by_user_id = $3)
|
|
1424
|
+
OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'
|
|
1425
|
+
AND (
|
|
1426
|
+
EXISTS (
|
|
1427
|
+
SELECT 1
|
|
1428
|
+
FROM weave.document_restricted_groups drg
|
|
1429
|
+
JOIN weave.restricted_group_user_memberships rgum
|
|
1430
|
+
ON rgum.organization_id = drg.organization_id
|
|
1431
|
+
AND rgum.restricted_group_id = drg.restricted_group_id
|
|
1432
|
+
AND rgum.user_id = $3
|
|
1433
|
+
WHERE drg.organization_id = d.organization_id
|
|
1434
|
+
AND drg.document_id = d.id
|
|
1435
|
+
)
|
|
1436
|
+
OR EXISTS (
|
|
1437
|
+
SELECT 1
|
|
1438
|
+
FROM weave.document_restricted_groups drg
|
|
1439
|
+
JOIN weave.restricted_group_team_memberships rgtm
|
|
1440
|
+
ON rgtm.organization_id = drg.organization_id
|
|
1441
|
+
AND rgtm.restricted_group_id = drg.restricted_group_id
|
|
1442
|
+
JOIN weave.org_team_memberships otm
|
|
1443
|
+
ON otm.organization_id = rgtm.organization_id
|
|
1444
|
+
AND otm.org_team_id = rgtm.org_team_id
|
|
1445
|
+
AND otm.user_id = $3
|
|
1446
|
+
WHERE drg.organization_id = d.organization_id
|
|
1447
|
+
AND drg.document_id = d.id
|
|
1448
|
+
)))
|
|
1449
|
+
)
|
|
1450
|
+
ORDER BY t.extracted_at ASC, t.id ASC
|
|
1451
|
+
LIMIT $5 OFFSET $4`;
|
|
1452
|
+
async function listAccessibleThreadsByDocument(client, args) {
|
|
1453
|
+
const result = await client.query({
|
|
1454
|
+
text: exports.listAccessibleThreadsByDocumentQuery,
|
|
1455
|
+
values: [args.organizationId, args.documentId, args.actingUserId, args.pageOffset, args.pageSize],
|
|
1456
|
+
rowMode: "array"
|
|
1457
|
+
});
|
|
1458
|
+
return result.rows.map(row => {
|
|
1459
|
+
return {
|
|
1460
|
+
id: row[0],
|
|
1461
|
+
organizationId: row[1],
|
|
1462
|
+
documentId: row[2],
|
|
1463
|
+
documentName: row[3],
|
|
1464
|
+
ingestionRunId: row[4],
|
|
1465
|
+
text: row[5],
|
|
1466
|
+
textOriginal: row[6],
|
|
1467
|
+
knowledgeType: row[7],
|
|
1468
|
+
facetFields: row[8],
|
|
1469
|
+
confidence: row[9],
|
|
1470
|
+
temporalValidity: row[10],
|
|
1471
|
+
classification: row[11],
|
|
1472
|
+
retrievalStatus: row[12],
|
|
1473
|
+
sourceLocation: row[13],
|
|
1474
|
+
supersededBy: row[14],
|
|
1475
|
+
supersedes: row[15],
|
|
1476
|
+
clusterId: row[16],
|
|
1477
|
+
extractedAt: row[17],
|
|
1478
|
+
approvedAt: row[18],
|
|
1479
|
+
approvedByUserId: row[19],
|
|
1480
|
+
edited: row[20],
|
|
1481
|
+
metadata: row[21]
|
|
1482
|
+
};
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1389
1485
|
exports.listPendingThreadsByRunQuery = `-- name: ListPendingThreadsByRun :many
|
|
1390
1486
|
SELECT
|
|
1391
1487
|
id,
|
|
@@ -2641,8 +2737,8 @@ WITH upsert AS (
|
|
|
2641
2737
|
embedding_provider_configuration_id,
|
|
2642
2738
|
classify_model_id,
|
|
2643
2739
|
classify_provider_configuration_id,
|
|
2644
|
-
|
|
2645
|
-
|
|
2740
|
+
create_thread_model_id,
|
|
2741
|
+
create_thread_provider_configuration_id,
|
|
2646
2742
|
extract_model_id,
|
|
2647
2743
|
extract_provider_configuration_id,
|
|
2648
2744
|
embed_model_id,
|
|
@@ -2651,7 +2747,7 @@ WITH upsert AS (
|
|
|
2651
2747
|
reconcile_provider_configuration_id,
|
|
2652
2748
|
diff_model_id,
|
|
2653
2749
|
diff_provider_configuration_id,
|
|
2654
|
-
|
|
2750
|
+
create_thread_loop_count,
|
|
2655
2751
|
updated_at
|
|
2656
2752
|
)
|
|
2657
2753
|
SELECT
|
|
@@ -2662,8 +2758,8 @@ SELECT
|
|
|
2662
2758
|
upsert.embedding_provider_configuration_id,
|
|
2663
2759
|
upsert.classify_model_id,
|
|
2664
2760
|
upsert.classify_provider_configuration_id,
|
|
2665
|
-
upsert.
|
|
2666
|
-
upsert.
|
|
2761
|
+
upsert.create_thread_model_id,
|
|
2762
|
+
upsert.create_thread_provider_configuration_id,
|
|
2667
2763
|
upsert.extract_model_id,
|
|
2668
2764
|
upsert.extract_provider_configuration_id,
|
|
2669
2765
|
upsert.embed_model_id,
|
|
@@ -2674,7 +2770,7 @@ SELECT
|
|
|
2674
2770
|
upsert.diff_provider_configuration_id,
|
|
2675
2771
|
cfg.embedding_dimension AS embedding_dimensions,
|
|
2676
2772
|
cfg.embedding_dimension AS embed_dimensions,
|
|
2677
|
-
upsert.
|
|
2773
|
+
upsert.create_thread_loop_count,
|
|
2678
2774
|
upsert.updated_at
|
|
2679
2775
|
FROM upsert
|
|
2680
2776
|
JOIN weave.database_config cfg
|
|
@@ -2697,8 +2793,8 @@ async function ensureOrganizationIngestionSettings(client, args) {
|
|
|
2697
2793
|
embeddingProviderConfigurationId: row[4],
|
|
2698
2794
|
classifyModelId: row[5],
|
|
2699
2795
|
classifyProviderConfigurationId: row[6],
|
|
2700
|
-
|
|
2701
|
-
|
|
2796
|
+
createThreadModelId: row[7],
|
|
2797
|
+
createThreadProviderConfigurationId: row[8],
|
|
2702
2798
|
extractModelId: row[9],
|
|
2703
2799
|
extractProviderConfigurationId: row[10],
|
|
2704
2800
|
embedModelId: row[11],
|
|
@@ -2709,7 +2805,7 @@ async function ensureOrganizationIngestionSettings(client, args) {
|
|
|
2709
2805
|
diffProviderConfigurationId: row[16],
|
|
2710
2806
|
embeddingDimensions: row[17],
|
|
2711
2807
|
embedDimensions: row[18],
|
|
2712
|
-
|
|
2808
|
+
createThreadLoopCount: row[19],
|
|
2713
2809
|
updatedAt: row[20]
|
|
2714
2810
|
};
|
|
2715
2811
|
}
|
|
@@ -2722,8 +2818,8 @@ SELECT
|
|
|
2722
2818
|
settings.embedding_provider_configuration_id,
|
|
2723
2819
|
settings.classify_model_id,
|
|
2724
2820
|
settings.classify_provider_configuration_id,
|
|
2725
|
-
settings.
|
|
2726
|
-
settings.
|
|
2821
|
+
settings.create_thread_model_id,
|
|
2822
|
+
settings.create_thread_provider_configuration_id,
|
|
2727
2823
|
settings.extract_model_id,
|
|
2728
2824
|
settings.extract_provider_configuration_id,
|
|
2729
2825
|
settings.embed_model_id,
|
|
@@ -2734,7 +2830,7 @@ SELECT
|
|
|
2734
2830
|
settings.diff_provider_configuration_id,
|
|
2735
2831
|
cfg.embedding_dimension AS embedding_dimensions,
|
|
2736
2832
|
cfg.embedding_dimension AS embed_dimensions,
|
|
2737
|
-
settings.
|
|
2833
|
+
settings.create_thread_loop_count,
|
|
2738
2834
|
settings.updated_at
|
|
2739
2835
|
FROM weave.org_ingestion_settings settings
|
|
2740
2836
|
JOIN weave.database_config cfg
|
|
@@ -2758,8 +2854,8 @@ async function getOrganizationIngestionSettings(client, args) {
|
|
|
2758
2854
|
embeddingProviderConfigurationId: row[4],
|
|
2759
2855
|
classifyModelId: row[5],
|
|
2760
2856
|
classifyProviderConfigurationId: row[6],
|
|
2761
|
-
|
|
2762
|
-
|
|
2857
|
+
createThreadModelId: row[7],
|
|
2858
|
+
createThreadProviderConfigurationId: row[8],
|
|
2763
2859
|
extractModelId: row[9],
|
|
2764
2860
|
extractProviderConfigurationId: row[10],
|
|
2765
2861
|
embedModelId: row[11],
|
|
@@ -2770,7 +2866,7 @@ async function getOrganizationIngestionSettings(client, args) {
|
|
|
2770
2866
|
diffProviderConfigurationId: row[16],
|
|
2771
2867
|
embeddingDimensions: row[17],
|
|
2772
2868
|
embedDimensions: row[18],
|
|
2773
|
-
|
|
2869
|
+
createThreadLoopCount: row[19],
|
|
2774
2870
|
updatedAt: row[20]
|
|
2775
2871
|
};
|
|
2776
2872
|
}
|
|
@@ -2789,8 +2885,8 @@ WITH cfg AS (
|
|
|
2789
2885
|
embedding_provider_configuration_id,
|
|
2790
2886
|
classify_model_id,
|
|
2791
2887
|
classify_provider_configuration_id,
|
|
2792
|
-
|
|
2793
|
-
|
|
2888
|
+
create_thread_model_id,
|
|
2889
|
+
create_thread_provider_configuration_id,
|
|
2794
2890
|
extract_model_id,
|
|
2795
2891
|
extract_provider_configuration_id,
|
|
2796
2892
|
embed_model_id,
|
|
@@ -2827,8 +2923,8 @@ WITH cfg AS (
|
|
|
2827
2923
|
embedding_provider_configuration_id = EXCLUDED.embedding_provider_configuration_id,
|
|
2828
2924
|
classify_model_id = EXCLUDED.classify_model_id,
|
|
2829
2925
|
classify_provider_configuration_id = EXCLUDED.classify_provider_configuration_id,
|
|
2830
|
-
|
|
2831
|
-
|
|
2926
|
+
create_thread_model_id = EXCLUDED.create_thread_model_id,
|
|
2927
|
+
create_thread_provider_configuration_id = EXCLUDED.create_thread_provider_configuration_id,
|
|
2832
2928
|
extract_model_id = EXCLUDED.extract_model_id,
|
|
2833
2929
|
extract_provider_configuration_id = EXCLUDED.extract_provider_configuration_id,
|
|
2834
2930
|
embed_model_id = EXCLUDED.embed_model_id,
|
|
@@ -2846,8 +2942,8 @@ WITH cfg AS (
|
|
|
2846
2942
|
embedding_provider_configuration_id,
|
|
2847
2943
|
classify_model_id,
|
|
2848
2944
|
classify_provider_configuration_id,
|
|
2849
|
-
|
|
2850
|
-
|
|
2945
|
+
create_thread_model_id,
|
|
2946
|
+
create_thread_provider_configuration_id,
|
|
2851
2947
|
extract_model_id,
|
|
2852
2948
|
extract_provider_configuration_id,
|
|
2853
2949
|
embed_model_id,
|
|
@@ -2856,7 +2952,7 @@ WITH cfg AS (
|
|
|
2856
2952
|
reconcile_provider_configuration_id,
|
|
2857
2953
|
diff_model_id,
|
|
2858
2954
|
diff_provider_configuration_id,
|
|
2859
|
-
|
|
2955
|
+
create_thread_loop_count,
|
|
2860
2956
|
updated_at
|
|
2861
2957
|
)
|
|
2862
2958
|
SELECT
|
|
@@ -2867,8 +2963,8 @@ SELECT
|
|
|
2867
2963
|
upsert.embedding_provider_configuration_id,
|
|
2868
2964
|
upsert.classify_model_id,
|
|
2869
2965
|
upsert.classify_provider_configuration_id,
|
|
2870
|
-
upsert.
|
|
2871
|
-
upsert.
|
|
2966
|
+
upsert.create_thread_model_id,
|
|
2967
|
+
upsert.create_thread_provider_configuration_id,
|
|
2872
2968
|
upsert.extract_model_id,
|
|
2873
2969
|
upsert.extract_provider_configuration_id,
|
|
2874
2970
|
upsert.embed_model_id,
|
|
@@ -2879,7 +2975,7 @@ SELECT
|
|
|
2879
2975
|
upsert.diff_provider_configuration_id,
|
|
2880
2976
|
cfg.embedding_dimension AS embedding_dimensions,
|
|
2881
2977
|
cfg.embedding_dimension AS embed_dimensions,
|
|
2882
|
-
upsert.
|
|
2978
|
+
upsert.create_thread_loop_count,
|
|
2883
2979
|
upsert.updated_at
|
|
2884
2980
|
FROM upsert
|
|
2885
2981
|
JOIN cfg
|
|
@@ -2902,8 +2998,8 @@ async function upsertOrganizationIngestionSettings(client, args) {
|
|
|
2902
2998
|
embeddingProviderConfigurationId: row[4],
|
|
2903
2999
|
classifyModelId: row[5],
|
|
2904
3000
|
classifyProviderConfigurationId: row[6],
|
|
2905
|
-
|
|
2906
|
-
|
|
3001
|
+
createThreadModelId: row[7],
|
|
3002
|
+
createThreadProviderConfigurationId: row[8],
|
|
2907
3003
|
extractModelId: row[9],
|
|
2908
3004
|
extractProviderConfigurationId: row[10],
|
|
2909
3005
|
embedModelId: row[11],
|
|
@@ -2914,7 +3010,7 @@ async function upsertOrganizationIngestionSettings(client, args) {
|
|
|
2914
3010
|
diffProviderConfigurationId: row[16],
|
|
2915
3011
|
embeddingDimensions: row[17],
|
|
2916
3012
|
embedDimensions: row[18],
|
|
2917
|
-
|
|
3013
|
+
createThreadLoopCount: row[19],
|
|
2918
3014
|
updatedAt: row[20]
|
|
2919
3015
|
};
|
|
2920
3016
|
}
|
|
@@ -2929,8 +3025,8 @@ WITH cfg AS (
|
|
|
2929
3025
|
organization_id,
|
|
2930
3026
|
classify_model_id,
|
|
2931
3027
|
classify_provider_configuration_id,
|
|
2932
|
-
|
|
2933
|
-
|
|
3028
|
+
create_thread_model_id,
|
|
3029
|
+
create_thread_provider_configuration_id,
|
|
2934
3030
|
extract_model_id,
|
|
2935
3031
|
extract_provider_configuration_id,
|
|
2936
3032
|
embed_model_id,
|
|
@@ -2939,7 +3035,7 @@ WITH cfg AS (
|
|
|
2939
3035
|
reconcile_provider_configuration_id,
|
|
2940
3036
|
diff_model_id,
|
|
2941
3037
|
diff_provider_configuration_id,
|
|
2942
|
-
|
|
3038
|
+
create_thread_loop_count
|
|
2943
3039
|
)
|
|
2944
3040
|
SELECT
|
|
2945
3041
|
$2,
|
|
@@ -2961,8 +3057,8 @@ WITH cfg AS (
|
|
|
2961
3057
|
SET
|
|
2962
3058
|
classify_model_id = EXCLUDED.classify_model_id,
|
|
2963
3059
|
classify_provider_configuration_id = EXCLUDED.classify_provider_configuration_id,
|
|
2964
|
-
|
|
2965
|
-
|
|
3060
|
+
create_thread_model_id = EXCLUDED.create_thread_model_id,
|
|
3061
|
+
create_thread_provider_configuration_id = EXCLUDED.create_thread_provider_configuration_id,
|
|
2966
3062
|
extract_model_id = EXCLUDED.extract_model_id,
|
|
2967
3063
|
extract_provider_configuration_id = EXCLUDED.extract_provider_configuration_id,
|
|
2968
3064
|
embed_model_id = EXCLUDED.embed_model_id,
|
|
@@ -2971,14 +3067,14 @@ WITH cfg AS (
|
|
|
2971
3067
|
reconcile_provider_configuration_id = EXCLUDED.reconcile_provider_configuration_id,
|
|
2972
3068
|
diff_model_id = EXCLUDED.diff_model_id,
|
|
2973
3069
|
diff_provider_configuration_id = EXCLUDED.diff_provider_configuration_id,
|
|
2974
|
-
|
|
3070
|
+
create_thread_loop_count = EXCLUDED.create_thread_loop_count,
|
|
2975
3071
|
updated_at = now()
|
|
2976
3072
|
RETURNING
|
|
2977
3073
|
organization_id,
|
|
2978
3074
|
classify_model_id,
|
|
2979
3075
|
classify_provider_configuration_id,
|
|
2980
|
-
|
|
2981
|
-
|
|
3076
|
+
create_thread_model_id,
|
|
3077
|
+
create_thread_provider_configuration_id,
|
|
2982
3078
|
extract_model_id,
|
|
2983
3079
|
extract_provider_configuration_id,
|
|
2984
3080
|
embed_model_id,
|
|
@@ -2987,15 +3083,15 @@ WITH cfg AS (
|
|
|
2987
3083
|
reconcile_provider_configuration_id,
|
|
2988
3084
|
diff_model_id,
|
|
2989
3085
|
diff_provider_configuration_id,
|
|
2990
|
-
|
|
3086
|
+
create_thread_loop_count,
|
|
2991
3087
|
updated_at
|
|
2992
3088
|
)
|
|
2993
3089
|
SELECT
|
|
2994
3090
|
upsert.organization_id,
|
|
2995
3091
|
upsert.classify_model_id,
|
|
2996
3092
|
upsert.classify_provider_configuration_id,
|
|
2997
|
-
upsert.
|
|
2998
|
-
upsert.
|
|
3093
|
+
upsert.create_thread_model_id,
|
|
3094
|
+
upsert.create_thread_provider_configuration_id,
|
|
2999
3095
|
upsert.extract_model_id,
|
|
3000
3096
|
upsert.extract_provider_configuration_id,
|
|
3001
3097
|
upsert.embed_model_id,
|
|
@@ -3006,7 +3102,7 @@ SELECT
|
|
|
3006
3102
|
upsert.diff_provider_configuration_id,
|
|
3007
3103
|
cfg.embedding_dimension AS embedding_dimensions,
|
|
3008
3104
|
cfg.embedding_dimension AS embed_dimensions,
|
|
3009
|
-
upsert.
|
|
3105
|
+
upsert.create_thread_loop_count,
|
|
3010
3106
|
upsert.updated_at
|
|
3011
3107
|
FROM upsert
|
|
3012
3108
|
JOIN cfg
|
|
@@ -3014,7 +3110,7 @@ JOIN cfg
|
|
|
3014
3110
|
async function upsertOrganizationIngestionStageSettings(client, args) {
|
|
3015
3111
|
const result = await client.query({
|
|
3016
3112
|
text: exports.upsertOrganizationIngestionStageSettingsQuery,
|
|
3017
|
-
values: [args.embedDimensions, args.organizationId, args.classifyModelId, args.classifyProviderConfigurationId, args.
|
|
3113
|
+
values: [args.embedDimensions, args.organizationId, args.classifyModelId, args.classifyProviderConfigurationId, args.createThreadModelId, args.createThreadProviderConfigurationId, args.extractModelId, args.extractProviderConfigurationId, args.embedModelId, args.embedProviderConfigurationId, args.reconcileModelId, args.reconcileProviderConfigurationId, args.diffModelId, args.diffProviderConfigurationId, args.createThreadLoopCount],
|
|
3018
3114
|
rowMode: "array"
|
|
3019
3115
|
});
|
|
3020
3116
|
if (result.rows.length !== 1) {
|
|
@@ -3025,8 +3121,8 @@ async function upsertOrganizationIngestionStageSettings(client, args) {
|
|
|
3025
3121
|
organizationId: row[0],
|
|
3026
3122
|
classifyModelId: row[1],
|
|
3027
3123
|
classifyProviderConfigurationId: row[2],
|
|
3028
|
-
|
|
3029
|
-
|
|
3124
|
+
createThreadModelId: row[3],
|
|
3125
|
+
createThreadProviderConfigurationId: row[4],
|
|
3030
3126
|
extractModelId: row[5],
|
|
3031
3127
|
extractProviderConfigurationId: row[6],
|
|
3032
3128
|
embedModelId: row[7],
|
|
@@ -3037,7 +3133,7 @@ async function upsertOrganizationIngestionStageSettings(client, args) {
|
|
|
3037
3133
|
diffProviderConfigurationId: row[12],
|
|
3038
3134
|
embeddingDimensions: row[13],
|
|
3039
3135
|
embedDimensions: row[14],
|
|
3040
|
-
|
|
3136
|
+
createThreadLoopCount: row[15],
|
|
3041
3137
|
updatedAt: row[16]
|
|
3042
3138
|
};
|
|
3043
3139
|
}
|
|
@@ -3053,8 +3149,8 @@ WITH cfg AS (
|
|
|
3053
3149
|
reasoning_provider_configuration_id,
|
|
3054
3150
|
classify_model_id,
|
|
3055
3151
|
classify_provider_configuration_id,
|
|
3056
|
-
|
|
3057
|
-
|
|
3152
|
+
create_thread_model_id,
|
|
3153
|
+
create_thread_provider_configuration_id,
|
|
3058
3154
|
extract_model_id,
|
|
3059
3155
|
extract_provider_configuration_id,
|
|
3060
3156
|
reconcile_model_id,
|
|
@@ -3090,10 +3186,10 @@ WITH cfg AS (
|
|
|
3090
3186
|
weave.org_ingestion_settings.classify_provider_configuration_id,
|
|
3091
3187
|
EXCLUDED.classify_provider_configuration_id
|
|
3092
3188
|
),
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
weave.org_ingestion_settings.
|
|
3096
|
-
EXCLUDED.
|
|
3189
|
+
create_thread_model_id = COALESCE(weave.org_ingestion_settings.create_thread_model_id, EXCLUDED.create_thread_model_id),
|
|
3190
|
+
create_thread_provider_configuration_id = COALESCE(
|
|
3191
|
+
weave.org_ingestion_settings.create_thread_provider_configuration_id,
|
|
3192
|
+
EXCLUDED.create_thread_provider_configuration_id
|
|
3097
3193
|
),
|
|
3098
3194
|
extract_model_id = COALESCE(weave.org_ingestion_settings.extract_model_id, EXCLUDED.extract_model_id),
|
|
3099
3195
|
extract_provider_configuration_id = COALESCE(
|
|
@@ -3119,8 +3215,8 @@ WITH cfg AS (
|
|
|
3119
3215
|
embedding_provider_configuration_id,
|
|
3120
3216
|
classify_model_id,
|
|
3121
3217
|
classify_provider_configuration_id,
|
|
3122
|
-
|
|
3123
|
-
|
|
3218
|
+
create_thread_model_id,
|
|
3219
|
+
create_thread_provider_configuration_id,
|
|
3124
3220
|
extract_model_id,
|
|
3125
3221
|
extract_provider_configuration_id,
|
|
3126
3222
|
embed_model_id,
|
|
@@ -3129,7 +3225,7 @@ WITH cfg AS (
|
|
|
3129
3225
|
reconcile_provider_configuration_id,
|
|
3130
3226
|
diff_model_id,
|
|
3131
3227
|
diff_provider_configuration_id,
|
|
3132
|
-
|
|
3228
|
+
create_thread_loop_count,
|
|
3133
3229
|
updated_at
|
|
3134
3230
|
)
|
|
3135
3231
|
SELECT
|
|
@@ -3140,8 +3236,8 @@ SELECT
|
|
|
3140
3236
|
upsert.embedding_provider_configuration_id,
|
|
3141
3237
|
upsert.classify_model_id,
|
|
3142
3238
|
upsert.classify_provider_configuration_id,
|
|
3143
|
-
upsert.
|
|
3144
|
-
upsert.
|
|
3239
|
+
upsert.create_thread_model_id,
|
|
3240
|
+
upsert.create_thread_provider_configuration_id,
|
|
3145
3241
|
upsert.extract_model_id,
|
|
3146
3242
|
upsert.extract_provider_configuration_id,
|
|
3147
3243
|
upsert.embed_model_id,
|
|
@@ -3152,7 +3248,7 @@ SELECT
|
|
|
3152
3248
|
upsert.diff_provider_configuration_id,
|
|
3153
3249
|
cfg.embedding_dimension AS embedding_dimensions,
|
|
3154
3250
|
cfg.embedding_dimension AS embed_dimensions,
|
|
3155
|
-
upsert.
|
|
3251
|
+
upsert.create_thread_loop_count,
|
|
3156
3252
|
upsert.updated_at
|
|
3157
3253
|
FROM upsert
|
|
3158
3254
|
JOIN cfg
|
|
@@ -3175,8 +3271,8 @@ async function syncOrganizationIngestionReasoningDefaults(client, args) {
|
|
|
3175
3271
|
embeddingProviderConfigurationId: row[4],
|
|
3176
3272
|
classifyModelId: row[5],
|
|
3177
3273
|
classifyProviderConfigurationId: row[6],
|
|
3178
|
-
|
|
3179
|
-
|
|
3274
|
+
createThreadModelId: row[7],
|
|
3275
|
+
createThreadProviderConfigurationId: row[8],
|
|
3180
3276
|
extractModelId: row[9],
|
|
3181
3277
|
extractProviderConfigurationId: row[10],
|
|
3182
3278
|
embedModelId: row[11],
|
|
@@ -3187,7 +3283,7 @@ async function syncOrganizationIngestionReasoningDefaults(client, args) {
|
|
|
3187
3283
|
diffProviderConfigurationId: row[16],
|
|
3188
3284
|
embeddingDimensions: row[17],
|
|
3189
3285
|
embedDimensions: row[18],
|
|
3190
|
-
|
|
3286
|
+
createThreadLoopCount: row[19],
|
|
3191
3287
|
updatedAt: row[20]
|
|
3192
3288
|
};
|
|
3193
3289
|
}
|
|
@@ -181,20 +181,20 @@ export interface SearchApprovedThreadsByEntitiesAndUserPermissionsRow {
|
|
|
181
181
|
conceptCluster: string;
|
|
182
182
|
}
|
|
183
183
|
export declare function searchApprovedThreadsByEntitiesAndUserPermissions(client: Client, args: SearchApprovedThreadsByEntitiesAndUserPermissionsArgs): Promise<SearchApprovedThreadsByEntitiesAndUserPermissionsRow[]>;
|
|
184
|
-
export declare const searchLeafConceptClustersBySimilarityQuery = "-- name: SearchLeafConceptClustersBySimilarity :many\nSELECT\n cc.id,\n cc.organization_id,\n cc.
|
|
184
|
+
export declare const searchLeafConceptClustersBySimilarityQuery = "-- name: SearchLeafConceptClustersBySimilarity :many\nSELECT\n cc.id,\n cc.organization_id,\n cc.scope_kind,\n cc.scope_key,\n cc.name,\n cc.description,\n cc.knowledge_type,\n cc.level,\n cc.parent_id,\n cc.thread_count,\n cc.consolidation_run_id,\n cc.created_at,\n cc.updated_at,\n similarity.score\nFROM weave.concept_clusters cc\nCROSS JOIN LATERAL (\n SELECT CAST(\n 1.0::double precision\n - (cc.embedding <=> $1::vector)::double precision\n AS double precision\n ) AS score\n) similarity\nWHERE cc.organization_id = $2\n AND cc.scope_kind = $3\n AND cc.scope_key = $4\n AND cc.level = 0\n AND cc.embedding IS NOT NULL\n AND similarity.score >= $5::double precision\nORDER BY score DESC, cc.updated_at DESC\nLIMIT $6";
|
|
185
185
|
export interface SearchLeafConceptClustersBySimilarityArgs {
|
|
186
186
|
queryEmbedding: string;
|
|
187
187
|
organizationId: string;
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
scopeKind: string;
|
|
189
|
+
scopeKey: string;
|
|
190
190
|
minSimilarity: number;
|
|
191
191
|
resultLimit: string;
|
|
192
192
|
}
|
|
193
193
|
export interface SearchLeafConceptClustersBySimilarityRow {
|
|
194
194
|
id: string;
|
|
195
195
|
organizationId: string;
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
scopeKind: string;
|
|
197
|
+
scopeKey: string;
|
|
198
198
|
name: string;
|
|
199
199
|
description: string;
|
|
200
200
|
knowledgeType: string;
|
|
@@ -207,12 +207,12 @@ export interface SearchLeafConceptClustersBySimilarityRow {
|
|
|
207
207
|
score: number;
|
|
208
208
|
}
|
|
209
209
|
export declare function searchLeafConceptClustersBySimilarity(client: Client, args: SearchLeafConceptClustersBySimilarityArgs): Promise<SearchLeafConceptClustersBySimilarityRow[]>;
|
|
210
|
-
export declare const searchConceptClusterThreadsBySimilarityQuery = "-- name: SearchConceptClusterThreadsBySimilarity :many\nSELECT\n t.id AS thread_id,\n t.text,\n t.knowledge_type,\n t.facet_fields,\n similarity.score,\n t.classification,\n t.document_id,\n d.filename AS document_name,\n t.source_location,\n t.approved_at,\n t.temporal_validity,\n COALESCE(entity_data.entities, '{}'::text[]) AS entities,\n COALESCE(rs.reinforcement_count, 0) AS reinforcement_count,\n cc.name AS concept_cluster\nFROM weave.concept_clusters cc\nCROSS JOIN LATERAL (\n SELECT CAST(\n 1.0::double precision\n - (cc.embedding <=> $1::vector)::double precision\n AS double precision\n ) AS score\n) similarity\nJOIN weave.threads t ON t.cluster_id = cc.id\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.thread_reinforcement_scores rs ON rs.thread_id = t.id\nLEFT JOIN LATERAL (\n SELECT array_agg(DISTINCT e.canonical ORDER BY e.canonical) AS entities\n FROM weave.thread_entities te\n JOIN weave.entities e ON e.id = te.entity_id\n WHERE te.thread_id = t.id\n) entity_data ON TRUE\nWHERE cc.organization_id = $2\n AND cc.
|
|
210
|
+
export declare const searchConceptClusterThreadsBySimilarityQuery = "-- name: SearchConceptClusterThreadsBySimilarity :many\nSELECT\n t.id AS thread_id,\n t.text,\n t.knowledge_type,\n t.facet_fields,\n similarity.score,\n t.classification,\n t.document_id,\n d.filename AS document_name,\n t.source_location,\n t.approved_at,\n t.temporal_validity,\n COALESCE(entity_data.entities, '{}'::text[]) AS entities,\n COALESCE(rs.reinforcement_count, 0) AS reinforcement_count,\n cc.name AS concept_cluster\nFROM weave.concept_clusters cc\nCROSS JOIN LATERAL (\n SELECT CAST(\n 1.0::double precision\n - (cc.embedding <=> $1::vector)::double precision\n AS double precision\n ) AS score\n) similarity\nJOIN weave.threads t ON t.cluster_id = cc.id\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.thread_reinforcement_scores rs ON rs.thread_id = t.id\nLEFT JOIN LATERAL (\n SELECT array_agg(DISTINCT e.canonical ORDER BY e.canonical) AS entities\n FROM weave.thread_entities te\n JOIN weave.entities e ON e.id = te.entity_id\n WHERE te.thread_id = t.id\n) entity_data ON TRUE\nWHERE cc.organization_id = $2\n AND cc.scope_kind = $3\n AND cc.scope_key = $4\n AND cc.level = 0\n AND cc.embedding IS NOT NULL\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n AND similarity.score >= $5::double precision\nORDER BY score DESC, t.approved_at DESC\nLIMIT $6";
|
|
211
211
|
export interface SearchConceptClusterThreadsBySimilarityArgs {
|
|
212
212
|
queryEmbedding: string;
|
|
213
213
|
organizationId: string;
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
scopeKind: string;
|
|
215
|
+
scopeKey: string;
|
|
216
216
|
minSimilarity: number;
|
|
217
217
|
resultLimit: string;
|
|
218
218
|
}
|
|
@@ -233,12 +233,12 @@ export interface SearchConceptClusterThreadsBySimilarityRow {
|
|
|
233
233
|
conceptCluster: string;
|
|
234
234
|
}
|
|
235
235
|
export declare function searchConceptClusterThreadsBySimilarity(client: Client, args: SearchConceptClusterThreadsBySimilarityArgs): Promise<SearchConceptClusterThreadsBySimilarityRow[]>;
|
|
236
|
-
export declare const searchConceptClusterThreadsBySimilarityAndUserPermissionsQuery = "-- name: SearchConceptClusterThreadsBySimilarityAndUserPermissions :many\nSELECT\n t.id AS thread_id,\n t.text,\n t.knowledge_type,\n t.facet_fields,\n similarity.score,\n t.classification,\n t.document_id,\n d.filename AS document_name,\n t.source_location,\n t.approved_at,\n t.temporal_validity,\n COALESCE(entity_data.entities, '{}'::text[]) AS entities,\n COALESCE(rs.reinforcement_count, 0) AS reinforcement_count,\n cc.name AS concept_cluster\nFROM weave.concept_clusters cc\nCROSS JOIN LATERAL (\n SELECT CAST(\n 1.0::double precision\n - (cc.embedding <=> $1::vector)::double precision\n AS double precision\n ) AS score\n) similarity\nJOIN weave.threads t ON t.cluster_id = cc.id\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.thread_reinforcement_scores rs ON rs.thread_id = t.id\nLEFT JOIN LATERAL (\n SELECT array_agg(DISTINCT e.canonical ORDER BY e.canonical) AS entities\n FROM weave.thread_entities te\n JOIN weave.entities e ON e.id = te.entity_id\n WHERE te.thread_id = t.id\n) entity_data ON TRUE\nWHERE cc.organization_id = $2\n AND cc.
|
|
236
|
+
export declare const searchConceptClusterThreadsBySimilarityAndUserPermissionsQuery = "-- name: SearchConceptClusterThreadsBySimilarityAndUserPermissions :many\nSELECT\n t.id AS thread_id,\n t.text,\n t.knowledge_type,\n t.facet_fields,\n similarity.score,\n t.classification,\n t.document_id,\n d.filename AS document_name,\n t.source_location,\n t.approved_at,\n t.temporal_validity,\n COALESCE(entity_data.entities, '{}'::text[]) AS entities,\n COALESCE(rs.reinforcement_count, 0) AS reinforcement_count,\n cc.name AS concept_cluster\nFROM weave.concept_clusters cc\nCROSS JOIN LATERAL (\n SELECT CAST(\n 1.0::double precision\n - (cc.embedding <=> $1::vector)::double precision\n AS double precision\n ) AS score\n) similarity\nJOIN weave.threads t ON t.cluster_id = cc.id\nJOIN weave.documents d ON d.id = t.document_id\nLEFT JOIN weave.thread_reinforcement_scores rs ON rs.thread_id = t.id\nLEFT JOIN LATERAL (\n SELECT array_agg(DISTINCT e.canonical ORDER BY e.canonical) AS entities\n FROM weave.thread_entities te\n JOIN weave.entities e ON e.id = te.entity_id\n WHERE te.thread_id = t.id\n) entity_data ON TRUE\nWHERE cc.organization_id = $2\n AND cc.scope_kind = $3\n AND cc.scope_key = $4\n AND cc.level = 0\n AND cc.embedding IS NOT NULL\n AND t.retrieval_status = 'THREAD_RETRIEVAL_STATUS_APPROVED'\n AND similarity.score >= $5::double precision\n AND (\n d.scope = 'DOCUMENT_SCOPE_ORG'\n OR (d.scope = 'DOCUMENT_SCOPE_PRIVATE'\n AND d.uploaded_by_user_id = $6)\n OR (d.scope = 'DOCUMENT_SCOPE_RESTRICTED'\n AND (\n EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_user_memberships rgum\n ON rgum.organization_id = drg.organization_id\n AND rgum.restricted_group_id = drg.restricted_group_id\n AND rgum.user_id = $6\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )\n OR EXISTS (\n SELECT 1\n FROM weave.document_restricted_groups drg\n JOIN weave.restricted_group_team_memberships rgtm\n ON rgtm.organization_id = drg.organization_id\n AND rgtm.restricted_group_id = drg.restricted_group_id\n JOIN weave.org_team_memberships otm\n ON otm.organization_id = rgtm.organization_id\n AND otm.org_team_id = rgtm.org_team_id\n AND otm.user_id = $6\n WHERE drg.organization_id = d.organization_id\n AND drg.document_id = d.id\n )))\n )\nORDER BY score DESC, t.approved_at DESC\nLIMIT $7";
|
|
237
237
|
export interface SearchConceptClusterThreadsBySimilarityAndUserPermissionsArgs {
|
|
238
238
|
queryEmbedding: string;
|
|
239
239
|
organizationId: string;
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
scopeKind: string;
|
|
241
|
+
scopeKey: string;
|
|
242
242
|
minSimilarity: number;
|
|
243
243
|
actingUserId: string;
|
|
244
244
|
resultLimit: string;
|