@sentry/junior-memory 0.131.0 → 0.133.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/db/schema.d.ts +21 -0
- package/dist/index.js +45 -9
- package/dist/index.js.map +1 -1
- package/migrations/0006_friendly_hydra.sql +4 -0
- package/migrations/meta/0006_snapshot.json +386 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +2 -2
- package/src/db/schema.ts +11 -1
- package/src/store.ts +42 -10
package/dist/db/schema.d.ts
CHANGED
|
@@ -121,6 +121,27 @@ export declare const juniorMemoryMemories: import("drizzle-orm/pg-core").PgTable
|
|
|
121
121
|
identity: undefined;
|
|
122
122
|
generated: undefined;
|
|
123
123
|
}, {}, {}>;
|
|
124
|
+
searchVector: import("drizzle-orm/pg-core").PgColumn<{
|
|
125
|
+
name: "search_vector";
|
|
126
|
+
tableName: "junior_memory_memories";
|
|
127
|
+
dataType: "custom";
|
|
128
|
+
columnType: "PgCustomColumn";
|
|
129
|
+
data: string;
|
|
130
|
+
driverParam: unknown;
|
|
131
|
+
notNull: false;
|
|
132
|
+
hasDefault: true;
|
|
133
|
+
isPrimaryKey: false;
|
|
134
|
+
isAutoincrement: false;
|
|
135
|
+
hasRuntimeDefault: false;
|
|
136
|
+
enumValues: undefined;
|
|
137
|
+
baseColumn: never;
|
|
138
|
+
identity: undefined;
|
|
139
|
+
generated: {
|
|
140
|
+
type: "always";
|
|
141
|
+
};
|
|
142
|
+
}, {}, {
|
|
143
|
+
pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
|
|
144
|
+
}>;
|
|
124
145
|
sourcePlatform: import("drizzle-orm/pg-core").PgColumn<{
|
|
125
146
|
name: "source_platform";
|
|
126
147
|
tableName: "junior_memory_memories";
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import { sql } from "drizzle-orm";
|
|
|
29
29
|
import {
|
|
30
30
|
bigint,
|
|
31
31
|
check,
|
|
32
|
+
customType,
|
|
32
33
|
index,
|
|
33
34
|
integer,
|
|
34
35
|
pgTable,
|
|
@@ -75,6 +76,11 @@ var memoryRuntimeContextSchema = z.union([
|
|
|
75
76
|
]);
|
|
76
77
|
|
|
77
78
|
// src/db/schema.ts
|
|
79
|
+
var tsvector = customType({
|
|
80
|
+
dataType() {
|
|
81
|
+
return "tsvector";
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
var juniorMemoryMemories = pgTable(
|
|
79
85
|
"junior_memory_memories",
|
|
80
86
|
{
|
|
@@ -85,6 +91,9 @@ var juniorMemoryMemories = pgTable(
|
|
|
85
91
|
subjectType: text("subject_type", { enum: MEMORY_SUBJECT_TYPES }).notNull(),
|
|
86
92
|
subjectKey: text("subject_key"),
|
|
87
93
|
content: text("content").notNull(),
|
|
94
|
+
searchVector: tsvector("search_vector").generatedAlwaysAs(
|
|
95
|
+
sql`to_tsvector('english', "content")`
|
|
96
|
+
),
|
|
88
97
|
sourcePlatform: text("source_platform", {
|
|
89
98
|
enum: MEMORY_SOURCE_PLATFORMS
|
|
90
99
|
}).notNull(),
|
|
@@ -105,7 +114,7 @@ var juniorMemoryMemories = pgTable(
|
|
|
105
114
|
index("junior_memory_memories_expiration_idx").on(table.expiresAtMs).where(
|
|
106
115
|
sql`${table.archivedAtMs} IS NULL AND ${table.expiresAtMs} IS NOT NULL`
|
|
107
116
|
),
|
|
108
|
-
index("junior_memory_memories_search_idx").using("gin",
|
|
117
|
+
index("junior_memory_memories_search_idx").using("gin", table.scope, table.scopeKey, table.searchVector).where(
|
|
109
118
|
sql`${table.archivedAtMs} IS NULL AND ${table.supersededAtMs} IS NULL AND ${table.supersededById} IS NULL`
|
|
110
119
|
),
|
|
111
120
|
uniqueIndex("junior_memory_memories_idempotency_idx").on(table.scope, table.scopeKey, table.idempotencyKey).where(
|
|
@@ -336,6 +345,8 @@ var DEFAULT_EXPIRED_ARCHIVE_LIMIT = 100;
|
|
|
336
345
|
var PREFERENCE_ADJUDICATION_CANDIDATE_LIMIT = 10;
|
|
337
346
|
var PREFERENCE_ADJUDICATION_VECTOR_LIMIT = 5;
|
|
338
347
|
var VECTOR_SEARCH_OVERFETCH = 4;
|
|
348
|
+
var LEXICAL_RANK_OVERFETCH = 4;
|
|
349
|
+
var MAX_LEXICAL_RANK_CANDIDATES = 1e3;
|
|
339
350
|
var MAX_MEMORY_CONTENT_CHARS = 4e3;
|
|
340
351
|
var EMBEDDING_METRIC = "cosine";
|
|
341
352
|
var nonEmptyStringSchema2 = z2.string().min(1);
|
|
@@ -388,6 +399,7 @@ var memoryRowSchema = z2.object({
|
|
|
388
399
|
id: z2.string().min(1),
|
|
389
400
|
idempotencyKey: optionalStringSchema,
|
|
390
401
|
observedAtMs: z2.coerce.number(),
|
|
402
|
+
searchVector: z2.string().optional(),
|
|
391
403
|
scope: z2.enum(MEMORY_SCOPES),
|
|
392
404
|
scopeKey: z2.string().min(1),
|
|
393
405
|
sourceKey: z2.string().min(1),
|
|
@@ -893,16 +905,40 @@ async function searchVisibleLexicalMemories(args) {
|
|
|
893
905
|
)
|
|
894
906
|
FROM unnest(tsvector_to_array(${queryVector})) AS query_terms(term)
|
|
895
907
|
)`;
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
908
|
+
const candidateLimit = Math.min(
|
|
909
|
+
MAX_LEXICAL_RANK_CANDIDATES,
|
|
910
|
+
args.limit * LEXICAL_RANK_OVERFETCH
|
|
911
|
+
);
|
|
912
|
+
const candidates = args.db.select().from(juniorMemoryMemories).where(
|
|
913
|
+
and(predicate, sql2`${juniorMemoryMemories.searchVector} @@ ${tsquery}`)
|
|
914
|
+
).orderBy(
|
|
903
915
|
desc(juniorMemoryMemories.observedAtMs),
|
|
904
916
|
asc(juniorMemoryMemories.id)
|
|
905
|
-
).limit(
|
|
917
|
+
).limit(candidateLimit).as("lexical_candidates");
|
|
918
|
+
const textRank = sql2`ts_rank_cd(${candidates.searchVector}, ${tsquery})`;
|
|
919
|
+
const rows = await args.db.select({
|
|
920
|
+
memory: {
|
|
921
|
+
archiveReason: candidates.archiveReason,
|
|
922
|
+
archivedAtMs: candidates.archivedAtMs,
|
|
923
|
+
content: candidates.content,
|
|
924
|
+
createdAtMs: candidates.createdAtMs,
|
|
925
|
+
expiresAtMs: candidates.expiresAtMs,
|
|
926
|
+
id: candidates.id,
|
|
927
|
+
idempotencyKey: candidates.idempotencyKey,
|
|
928
|
+
kind: candidates.kind,
|
|
929
|
+
observedAtMs: candidates.observedAtMs,
|
|
930
|
+
scope: candidates.scope,
|
|
931
|
+
scopeKey: candidates.scopeKey,
|
|
932
|
+
searchVector: candidates.searchVector,
|
|
933
|
+
sourceKey: candidates.sourceKey,
|
|
934
|
+
sourcePlatform: candidates.sourcePlatform,
|
|
935
|
+
subjectKey: candidates.subjectKey,
|
|
936
|
+
subjectType: candidates.subjectType,
|
|
937
|
+
supersededAtMs: candidates.supersededAtMs,
|
|
938
|
+
supersededById: candidates.supersededById
|
|
939
|
+
},
|
|
940
|
+
textRank
|
|
941
|
+
}).from(candidates).orderBy(desc(textRank), desc(candidates.observedAtMs), asc(candidates.id)).limit(args.limit);
|
|
906
942
|
const ranks = denseRanks(rows, (row) => Number(row.textRank));
|
|
907
943
|
return rows.map((row, index2) => ({
|
|
908
944
|
lexical: { rank: ranks[index2] },
|