Skip to content

Commit b453d11

Browse files
committed
improvement(kb): removed zustand cache syncing in kb, added chunk text tokenizer
1 parent c77268c commit b453d11

File tree

21 files changed

+690
-1642
lines changed

21 files changed

+690
-1642
lines changed

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components/create-chunk-modal/create-chunk-modal.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useRef, useState } from 'react'
44
import { createLogger } from '@sim/logger'
5+
import { useQueryClient } from '@tanstack/react-query'
56
import { AlertCircle } from 'lucide-react'
67
import {
78
Button,
@@ -13,7 +14,8 @@ import {
1314
ModalHeader,
1415
Textarea,
1516
} from '@/components/emcn'
16-
import type { ChunkData, DocumentData } from '@/stores/knowledge/store'
17+
import type { DocumentData } from '@/lib/knowledge/types'
18+
import { knowledgeKeys } from '@/hooks/queries/knowledge'
1719

1820
const logger = createLogger('CreateChunkModal')
1921

@@ -22,16 +24,15 @@ interface CreateChunkModalProps {
2224
onOpenChange: (open: boolean) => void
2325
document: DocumentData | null
2426
knowledgeBaseId: string
25-
onChunkCreated?: (chunk: ChunkData) => void
2627
}
2728

2829
export function CreateChunkModal({
2930
open,
3031
onOpenChange,
3132
document,
3233
knowledgeBaseId,
33-
onChunkCreated,
3434
}: CreateChunkModalProps) {
35+
const queryClient = useQueryClient()
3536
const [content, setContent] = useState('')
3637
const [isCreating, setIsCreating] = useState(false)
3738
const [error, setError] = useState<string | null>(null)
@@ -77,9 +78,9 @@ export function CreateChunkModal({
7778
if (result.success && result.data) {
7879
logger.info('Chunk created successfully:', result.data.id)
7980

80-
if (onChunkCreated) {
81-
onChunkCreated(result.data)
82-
}
81+
await queryClient.invalidateQueries({
82+
queryKey: knowledgeKeys.detail(knowledgeBaseId),
83+
})
8384

8485
onClose()
8586
} else {
@@ -96,7 +97,6 @@ export function CreateChunkModal({
9697

9798
const onClose = () => {
9899
onOpenChange(false)
99-
// Reset form state when modal closes
100100
setContent('')
101101
setError(null)
102102
setShowUnsavedChangesAlert(false)

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components/delete-chunk-modal/delete-chunk-modal.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import { useState } from 'react'
44
import { createLogger } from '@sim/logger'
5+
import { useQueryClient } from '@tanstack/react-query'
56
import { Button, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from '@/components/emcn'
6-
import type { ChunkData } from '@/stores/knowledge/store'
7+
import type { ChunkData } from '@/lib/knowledge/types'
8+
import { knowledgeKeys } from '@/hooks/queries/knowledge'
79

810
const logger = createLogger('DeleteChunkModal')
911

@@ -13,7 +15,6 @@ interface DeleteChunkModalProps {
1315
documentId: string
1416
isOpen: boolean
1517
onClose: () => void
16-
onChunkDeleted?: () => void
1718
}
1819

1920
export function DeleteChunkModal({
@@ -22,8 +23,8 @@ export function DeleteChunkModal({
2223
documentId,
2324
isOpen,
2425
onClose,
25-
onChunkDeleted,
2626
}: DeleteChunkModalProps) {
27+
const queryClient = useQueryClient()
2728
const [isDeleting, setIsDeleting] = useState(false)
2829

2930
const handleDeleteChunk = async () => {
@@ -47,16 +48,17 @@ export function DeleteChunkModal({
4748

4849
if (result.success) {
4950
logger.info('Chunk deleted successfully:', chunk.id)
50-
if (onChunkDeleted) {
51-
onChunkDeleted()
52-
}
51+
52+
await queryClient.invalidateQueries({
53+
queryKey: knowledgeKeys.detail(knowledgeBaseId),
54+
})
55+
5356
onClose()
5457
} else {
5558
throw new Error(result.error || 'Failed to delete chunk')
5659
}
5760
} catch (err) {
5861
logger.error('Error deleting chunk:', err)
59-
// You might want to show an error state here
6062
} finally {
6163
setIsDeleting(false)
6264
}

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components/document-tags-modal/document-tags-modal.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
import { cn } from '@/lib/core/utils/cn'
1919
import { ALL_TAG_SLOTS, type AllTagSlot, MAX_TAG_SLOTS } from '@/lib/knowledge/constants'
2020
import type { DocumentTag } from '@/lib/knowledge/tags/types'
21+
import type { DocumentData } from '@/lib/knowledge/types'
2122
import {
2223
type TagDefinition,
2324
useKnowledgeBaseTagDefinitions,
2425
} from '@/hooks/use-knowledge-base-tag-definitions'
2526
import { useNextAvailableSlot } from '@/hooks/use-next-available-slot'
2627
import { type TagDefinitionInput, useTagDefinitions } from '@/hooks/use-tag-definitions'
27-
import { type DocumentData, useKnowledgeStore } from '@/stores/knowledge/store'
2828

2929
const logger = createLogger('DocumentTagsModal')
3030

@@ -93,8 +93,6 @@ export function DocumentTagsModal({
9393
documentData,
9494
onDocumentUpdate,
9595
}: DocumentTagsModalProps) {
96-
const { updateDocument: updateDocumentInStore } = useKnowledgeStore()
97-
9896
const documentTagHook = useTagDefinitions(knowledgeBaseId, documentId)
9997
const kbTagHook = useKnowledgeBaseTagDefinitions(knowledgeBaseId)
10098
const { getNextAvailableSlot: getServerNextSlot } = useNextAvailableSlot(knowledgeBaseId)
@@ -171,23 +169,14 @@ export function DocumentTagsModal({
171169
throw new Error('Failed to update document tags')
172170
}
173171

174-
updateDocumentInStore(knowledgeBaseId, documentId, tagData as Record<string, string>)
175172
onDocumentUpdate?.(tagData as Record<string, string>)
176-
177173
await fetchTagDefinitions()
178174
} catch (error) {
179175
logger.error('Error updating document tags:', error)
180176
throw error
181177
}
182178
},
183-
[
184-
documentData,
185-
knowledgeBaseId,
186-
documentId,
187-
updateDocumentInStore,
188-
fetchTagDefinitions,
189-
onDocumentUpdate,
190-
]
179+
[documentData, knowledgeBaseId, documentId, fetchTagDefinitions, onDocumentUpdate]
191180
)
192181

193182
const handleRemoveTag = async (index: number) => {

0 commit comments

Comments
 (0)