@sentry/junior-memory 0.130.0 → 0.132.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.
@@ -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", sql`to_tsvector('english', ${table.content})`).where(
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(
@@ -204,16 +213,11 @@ function rankMemoryMatches(matches, options) {
204
213
  }
205
214
  byId.set(match.memory.id, {
206
215
  ...existing,
207
- exactIdentifier: existing.exactIdentifier || match.exactIdentifier,
208
216
  ...match.lexical ? { lexical: match.lexical } : {},
209
217
  ...match.vector ? { vector: match.vector } : {}
210
218
  });
211
219
  }
212
220
  return [...byId.values()].sort((left, right) => {
213
- const identifierDelta = Number(right.exactIdentifier) - Number(left.exactIdentifier);
214
- if (identifierDelta !== 0) {
215
- return identifierDelta;
216
- }
217
221
  const scoreDelta = matchScore(right) - matchScore(left);
218
222
  if (scoreDelta !== 0) {
219
223
  return scoreDelta;
@@ -393,6 +397,7 @@ var memoryRowSchema = z2.object({
393
397
  id: z2.string().min(1),
394
398
  idempotencyKey: optionalStringSchema,
395
399
  observedAtMs: z2.coerce.number(),
400
+ searchVector: z2.string().optional(),
396
401
  scope: z2.enum(MEMORY_SCOPES),
397
402
  scopeKey: z2.string().min(1),
398
403
  sourceKey: z2.string().min(1),
@@ -649,14 +654,6 @@ async function archiveExpiredMemoryBatch(args) {
649
654
  });
650
655
  return { archivedCount: archivedIds.length };
651
656
  }
652
- function structuredQueryIdentifiers(query) {
653
- const matches = query.toLowerCase().match(
654
- /(?:[a-z0-9][a-z0-9._-]*\/)+[a-z0-9][a-z0-9._-]*|[a-z0-9]+(?:[._][a-z0-9]+)+|[a-z0-9]+(?:-[a-z0-9]+){2,}/g
655
- ) ?? [];
656
- return [
657
- ...new Set(matches.map((identifier) => identifier.replace(/\.+$/, "")))
658
- ];
659
- }
660
657
  function denseRanks(values, key) {
661
658
  let previous;
662
659
  let rank = 0;
@@ -906,39 +903,18 @@ async function searchVisibleLexicalMemories(args) {
906
903
  )
907
904
  FROM unnest(tsvector_to_array(${queryVector})) AS query_terms(term)
908
905
  )`;
909
- const textsearch = sql2`to_tsvector('english', ${juniorMemoryMemories.content})`;
906
+ const textsearch = juniorMemoryMemories.searchVector;
910
907
  const textRank = sql2`ts_rank_cd(${textsearch}, ${tsquery})`;
911
- const identifiers = structuredQueryIdentifiers(args.query);
912
- const contentTokens = sql2`regexp_split_to_array(lower(${juniorMemoryMemories.content}), '[^a-z0-9._/-]+')`;
913
- const identifierArray = identifiers.length > 0 ? sql2`ARRAY[${sql2.join(
914
- identifiers.map((identifier) => sql2`${identifier}`),
915
- sql2`, `
916
- )}]::text[]` : void 0;
917
- const exactIdentifierMatch = identifierArray !== void 0 ? sql2`EXISTS (
918
- SELECT 1
919
- FROM unnest(${contentTokens}) AS content_token(value)
920
- CROSS JOIN unnest(${identifierArray}) AS query_identifier(value)
921
- WHERE strpos(
922
- '/' || regexp_replace(content_token.value, '\\.+$', '') || '/',
923
- '/' || query_identifier.value || '/'
924
- ) > 0
925
- )` : sql2`false`;
926
908
  const rows = await args.db.select({
927
- exactIdentifierMatch,
928
909
  memory: juniorMemoryMemories,
929
910
  textRank
930
911
  }).from(juniorMemoryMemories).where(and(predicate, sql2`${textsearch} @@ ${tsquery}`)).orderBy(
931
- ...identifiers.length > 0 ? [desc(exactIdentifierMatch)] : [],
932
912
  desc(textRank),
933
913
  desc(juniorMemoryMemories.observedAtMs),
934
914
  asc(juniorMemoryMemories.id)
935
915
  ).limit(args.limit);
936
- const ranks = denseRanks(
937
- rows,
938
- (row) => `${row.exactIdentifierMatch}:${Number(row.textRank)}`
939
- );
916
+ const ranks = denseRanks(rows, (row) => Number(row.textRank));
940
917
  return rows.map((row, index2) => ({
941
- exactIdentifier: row.exactIdentifierMatch,
942
918
  lexical: { rank: ranks[index2] },
943
919
  memory: parseMemoryRow(row.memory),
944
920
  sourceKey: row.memory.sourceKey
@@ -993,7 +969,6 @@ async function searchVisibleVectorMemories(args) {
993
969
  }
994
970
  return [
995
971
  {
996
- exactIdentifier: false,
997
972
  memory: parseMemoryRow(row.memory),
998
973
  sourceKey: row.memory.sourceKey,
999
974
  vector: {