@meaningfully/ui 0.0.3 → 0.0.4

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.
@@ -27,6 +27,37 @@
27
27
  displayCount += 10;
28
28
  };
29
29
 
30
+ // copied from https://github.com/run-llama/LlamaIndexTS/blob/main/packages/providers/storage/weaviate/src/sanitize.ts
31
+ // weaviate requires property names (i.e. metadata column names) to start with a lowercase letter or underscore,
32
+ // and only contain letters, numbers, and underscores.
33
+ // If weaviate is used as the vector store, metadata column names will be sanitized on upload,
34
+ // so we need to look for the sanitized version when displaying results.
35
+ // If another store is used, the original names will be preserved, and so this won't get called.
36
+ const sanitizePropertyName = (name: string): string => {
37
+ // Replace invalid characters with underscores
38
+ let sanitized = name.replace(/[^_A-Za-z0-9]/g, "_");
39
+
40
+ // Ensure it starts with a letter or underscore
41
+ if (!/^[_A-Za-z]/.test(sanitized)) {
42
+ sanitized = "_" + sanitized;
43
+ }
44
+
45
+ // Remove consecutive underscores
46
+ sanitized = sanitized.replace(/_+/g, "_");
47
+
48
+ // Remove trailing underscores
49
+ sanitized = sanitized.replace(/_+$/, "");
50
+
51
+ // Ensure it's not empty
52
+ if (!sanitized) {
53
+ sanitized = "_property";
54
+ }
55
+ // lowercase first letter to match weaviate behavior
56
+ sanitized = sanitized.charAt(0).toLowerCase() + sanitized.slice(1);
57
+
58
+ return sanitized;
59
+ };
60
+
30
61
  // Function to download results as CSV
31
62
  const downloadCSV = () => {
32
63
  if (results.length === 0) return;
@@ -39,8 +70,10 @@
39
70
  csvRow[textColumn] = row[textColumn] || '';
40
71
 
41
72
  // Add metadata columns
73
+ // check the sanitized version if the original doesn't exist
74
+ // certain characters aren't allowed in weaviate property names -- if present, and if weaviate is used as storage, they will be returned as sanitized.
42
75
  metadataColumns.forEach(column => {
43
- csvRow[column] = row[column] || '';
76
+ csvRow[column] = row[column] || row[sanitizePropertyName(column)] || '';
44
77
  });
45
78
 
46
79
  // Add similarity column, formatted as percentage
@@ -21,6 +21,38 @@
21
21
  // text column is always called text internally, but we rename just the header.
22
22
  let columns = $derived([textColumn, ...metadataColumns, ...(showSimilarity ? ['similarity'] : [])]);
23
23
 
24
+
25
+ // copied from https://github.com/run-llama/LlamaIndexTS/blob/main/packages/providers/storage/weaviate/src/sanitize.ts
26
+ // weaviate requires property names (i.e. metadata column names) to start with a lowercase letter or underscore,
27
+ // and only contain letters, numbers, and underscores.
28
+ // If weaviate is used as the vector store, metadata column names will be sanitized on upload,
29
+ // so we need to look for the sanitized version when displaying results.
30
+ // If another store is used, the original names will be preserved, and so this won't get called.
31
+ const sanitizePropertyNameForWeaviate = (name: string): string => {
32
+ // Replace invalid characters with underscores
33
+ let sanitized = name.replace(/[^_A-Za-z0-9]/g, "_");
34
+
35
+ // Ensure it starts with a letter or underscore
36
+ if (!/^[_A-Za-z]/.test(sanitized)) {
37
+ sanitized = "_" + sanitized;
38
+ }
39
+
40
+ // Remove consecutive underscores
41
+ sanitized = sanitized.replace(/_+/g, "_");
42
+
43
+ // Remove trailing underscores
44
+ sanitized = sanitized.replace(/_+$/, "");
45
+
46
+ // Ensure it's not empty
47
+ if (!sanitized) {
48
+ sanitized = "_property";
49
+ }
50
+ // lowercase first letter to match weaviate behavior
51
+ sanitized = sanitized.charAt(0).toLowerCase() + sanitized.slice(1);
52
+
53
+ return sanitized;
54
+ };
55
+
24
56
  function sanitizeAndFormatText(text: string): string {
25
57
  text = text.trim().replace(/^\\n/, '').replace(/\\n$/, '');
26
58
  // First escape special characters
@@ -66,12 +98,12 @@
66
98
  <td class="px-4 py-2">
67
99
  {#if column === 'similarity' && row[column] !== undefined}
68
100
  {(row[column] * 100).toFixed(1)}%
69
- {:else if column === textColumn}
70
- {@html sanitizeAndFormatText(row[column] || '')}
71
- {:else if is_link(row[column])}
72
- {@html linkify(row[column])}
101
+ {:else if column === textColumn || sanitizePropertyNameForWeaviate(column) === textColumn}
102
+ {@html sanitizeAndFormatText(row[column] || row[sanitizePropertyNameForWeaviate(column)] || '')}
103
+ {:else if is_link(row[column] || row[sanitizePropertyNameForWeaviate(column)] )}
104
+ {@html linkify(row[column] || row[sanitizePropertyNameForWeaviate(column)] )}
73
105
  {:else}
74
- {(row[column]) || ''}
106
+ {row[column] || row[sanitizePropertyNameForWeaviate(column)] || ''}
75
107
  {/if}
76
108
  </td>
77
109
  {/each}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meaningfully/ui",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "description": "Svelte components for meaningfully semantic search",
6
6
  "repo": "https://github.com/jeremybmerrill/meaningfully-ui",