database

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunksDBHandler

type ChunksDBHandler struct {
	// contains filtered or unexported fields
}

ChunksDBHandler handles chunk-related database operations

func NewChunksDBHandler

func NewChunksDBHandler(db *helper.Database, edgesHandler *EdgesDBHandler, embeddingDim int, force bool) (*ChunksDBHandler, error)

NewChunksDBHandler creates a new chunks database handler. It initializes the database connection and loads chunk-related SQL functions. If force is true, it will reload the SQL functions even if they already exist.

func (*ChunksDBHandler) ChangeIndexType

func (h *ChunksDBHandler) ChangeIndexType(ctx context.Context, indexType string, params map[string]interface{}) error

ChangeIndexType changes the vector index type between HNSW and IVFFlat indexType: "hnsw" or "ivfflat" params: optional parameters for index creation

  • For HNSW: "m" (int, default 16), "ef_construction" (int, default 64)
  • For IVFFlat: "lists" (int, default 100)

func (*ChunksDBHandler) CreateTable

func (h *ChunksDBHandler) CreateTable(embeddingDim int) error

CreateTable creates the 'chunks' table in the database. If the table already exists, it does not create it again. It also creates all necessary extensions, indexes, and triggers.

func (*ChunksDBHandler) DeleteChunk

func (h *ChunksDBHandler) DeleteChunk(id uuid.UUID) error

DeleteChunk deletes a chunk by ID

func (*ChunksDBHandler) InsertChunk

func (h *ChunksDBHandler) InsertChunk(chunk *model.Chunk) error

InsertChunk inserts a new chunk

func (*ChunksDBHandler) SelectAllChunksByDocument

func (h *ChunksDBHandler) SelectAllChunksByDocument(documentRID uuid.UUID) ([]*model.Chunk, error)

SelectAllChunksByDocument retrieves all chunks for a document

func (*ChunksDBHandler) SelectAllChunksByPathAncestor

func (h *ChunksDBHandler) SelectAllChunksByPathAncestor(path string) ([]*model.Chunk, error)

SelectAllChunksByPathAncestor retrieves chunks that are ancestors of the given path

func (*ChunksDBHandler) SelectAllChunksByPathDescendant

func (h *ChunksDBHandler) SelectAllChunksByPathDescendant(path string) ([]*model.Chunk, error)

SelectAllChunksByPathDescendant retrieves chunks that are descendants of the given path

func (*ChunksDBHandler) SelectChunk

func (h *ChunksDBHandler) SelectChunk(id uuid.UUID) (*model.Chunk, error)

SelectChunk retrieves a chunk by ID

func (*ChunksDBHandler) SelectChunksBySimilarity

func (h *ChunksDBHandler) SelectChunksBySimilarity(embedding []float32, limit int, threshold float64, documentRIDs []uuid.UUID) ([]*model.Chunk, error)

SelectChunksBySimilarity performs vector similarity search If documentRIDs is nil or empty, searches across all documents

func (*ChunksDBHandler) SelectChunksBySimilarityWithContext

func (h *ChunksDBHandler) SelectChunksBySimilarityWithContext(
	embedding []float32,
	limit int,
	includeAncestors bool,
	includeDescendants bool,
	threshold float64,
	documentRIDs []uuid.UUID,
) ([]*model.Chunk, error)

SelectChunksBySimilarityWithContext performs vector similarity search with hierarchical context If documentRIDs is nil or empty, searches across all documents

func (*ChunksDBHandler) SelectSiblingChunks

func (h *ChunksDBHandler) SelectSiblingChunks(path string) ([]*model.Chunk, error)

SelectSiblingChunks retrieves chunks that are siblings of the given path (same parent, same level)

func (*ChunksDBHandler) UpdateChunkEmbedding

func (h *ChunksDBHandler) UpdateChunkEmbedding(id uuid.UUID, embedding []float32) error

UpdateChunkEmbedding updates the embedding of a chunk

type ChunksDBHandlerFunctions

type ChunksDBHandlerFunctions interface {
	InsertChunk(chunk *model.Chunk) error
	SelectChunk(id uuid.UUID) (*model.Chunk, error)
	SelectAllChunksByDocument(documentRID uuid.UUID) ([]*model.Chunk, error)
	SelectAllChunksByPathDescendant(path string) ([]*model.Chunk, error)
	SelectAllChunksByPathAncestor(path string) ([]*model.Chunk, error)
	SelectChunksBySimilarity(embedding []float32, limit int, threshold float64, documentRIDs []uuid.UUID) ([]*model.Chunk, error)
	SelectChunksBySimilarityWithContext(embedding []float32, limit int, includeAncestors bool, includeDescendants bool, threshold float64, documentRIDs []uuid.UUID) ([]*model.Chunk, error)
	DeleteChunk(id uuid.UUID) error
	UpdateChunkEmbedding(id uuid.UUID, embedding []float32) error
}

ChunksDBHandlerFunctions defines the interface for Chunks database operations.

type DocumentsDBHandler

type DocumentsDBHandler struct {
	// contains filtered or unexported fields
}

DocumentsDBHandler handles document-related database operations

func NewDocumentsDBHandler

func NewDocumentsDBHandler(db *helper.Database, force bool) (*DocumentsDBHandler, error)

NewDocumentsDBHandler creates a new documents database handler. It initializes the database connection and loads document-related SQL functions. If force is true, it will reload the SQL functions even if they already exist.

func (*DocumentsDBHandler) CreateTable

func (h *DocumentsDBHandler) CreateTable() error

CreateTable creates the 'documents' table in the database. If the table already exists, it does not create it again. It also creates all necessary indexes and triggers.

func (*DocumentsDBHandler) DeleteDocument

func (h *DocumentsDBHandler) DeleteDocument(rid uuid.UUID) error

DeleteDocument deletes a document by RID

func (*DocumentsDBHandler) InsertDocument

func (h *DocumentsDBHandler) InsertDocument(doc *model.Document) error

InsertDocument inserts a new document

func (*DocumentsDBHandler) SelectAllDocuments

func (h *DocumentsDBHandler) SelectAllDocuments(lastCreatedAt *time.Time, limit int) ([]*model.Document, error)

SelectAllDocuments retrieves all documents with pagination

func (*DocumentsDBHandler) SelectDocument

func (h *DocumentsDBHandler) SelectDocument(rid uuid.UUID) (*model.Document, error)

SelectDocument retrieves a document by RID

func (*DocumentsDBHandler) SelectDocumentsBySearch

func (h *DocumentsDBHandler) SelectDocumentsBySearch(searchTerm string, limit int) ([]*model.Document, error)

SelectDocumentsBySearch searches documents by title or source

func (*DocumentsDBHandler) UpdateDocument

func (h *DocumentsDBHandler) UpdateDocument(doc *model.Document) error

UpdateDocument updates a document

type DocumentsDBHandlerFunctions

type DocumentsDBHandlerFunctions interface {
	InsertDocument(doc *model.Document) error
	SelectDocument(rid uuid.UUID) (*model.Document, error)
	SelectAllDocuments(lastCreatedAt *time.Time, limit int) ([]*model.Document, error)
	SelectDocumentsBySearch(searchTerm string, limit int) ([]*model.Document, error)
	UpdateDocument(doc *model.Document) error
	DeleteDocument(rid uuid.UUID) error
}

DocumentsDBHandlerFunctions defines the interface for Documents database operations.

type EdgesDBHandler

type EdgesDBHandler struct {
	// contains filtered or unexported fields
}

EdgesDBHandler handles edge-related database operations

func NewEdgesDBHandler

func NewEdgesDBHandler(db *helper.Database, force bool) (*EdgesDBHandler, error)

NewEdgesDBHandler creates a new edges database handler. It initializes the database connection and loads edge-related SQL functions. If force is true, it will reload the SQL functions even if they already exist.

func (*EdgesDBHandler) CreateTable

func (h *EdgesDBHandler) CreateTable() error

CreateTable creates the 'edges' table in the database. If the table already exists, it does not create it again. It also creates the edge_type enum and all necessary indexes.

func (*EdgesDBHandler) DeleteEdge

func (h *EdgesDBHandler) DeleteEdge(id uuid.UUID) error

DeleteEdge deletes an edge by ID

func (*EdgesDBHandler) InsertEdge

func (h *EdgesDBHandler) InsertEdge(edge *model.Edge) error

InsertEdge inserts a new edge

func (*EdgesDBHandler) SelectEdge

func (h *EdgesDBHandler) SelectEdge(id uuid.UUID) (*model.Edge, error)

SelectEdge retrieves an edge by ID

func (*EdgesDBHandler) SelectEdgesConnectedToChunk

func (h *EdgesDBHandler) SelectEdgesConnectedToChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.EdgeConnection, error)

SelectEdgesConnectedToChunk retrieves all edges connected to a chunk (both directions)

func (*EdgesDBHandler) SelectEdgesFromChunk

func (h *EdgesDBHandler) SelectEdgesFromChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)

SelectEdgesFromChunk retrieves edges originating from a chunk

func (*EdgesDBHandler) SelectEdgesFromEntity

func (h *EdgesDBHandler) SelectEdgesFromEntity(entityID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)

SelectEdgesFromEntity retrieves edges originating from an entity

func (*EdgesDBHandler) SelectEdgesToChunk

func (h *EdgesDBHandler) SelectEdgesToChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)

SelectEdgesToChunk retrieves edges targeting a chunk

func (*EdgesDBHandler) SelectEdgesToEntity

func (h *EdgesDBHandler) SelectEdgesToEntity(entityID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)

SelectEdgesToEntity retrieves edges targeting an entity

func (*EdgesDBHandler) TraverseBFSFromChunk

func (h *EdgesDBHandler) TraverseBFSFromChunk(startChunkID uuid.UUID, maxDepth int, edgeType *model.EdgeType) ([]*model.TraversalNode, error)

TraverseBFSFromChunk performs breadth-first search from a starting chunk

func (*EdgesDBHandler) UpdateEdgeWeight

func (h *EdgesDBHandler) UpdateEdgeWeight(id uuid.UUID, weight float64) error

UpdateEdgeWeight updates the weight of an edge

type EdgesDBHandlerFunctions

type EdgesDBHandlerFunctions interface {
	InsertEdge(edge *model.Edge) error
	SelectEdge(id uuid.UUID) (*model.Edge, error)
	SelectEdgesFromChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)
	SelectEdgesToChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)
	SelectEdgesConnectedToChunk(chunkID uuid.UUID, edgeType *model.EdgeType) ([]*model.EdgeConnection, error)
	SelectEdgesFromEntity(entityID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)
	SelectEdgesToEntity(entityID uuid.UUID, edgeType *model.EdgeType) ([]*model.Edge, error)
	DeleteEdge(id uuid.UUID) error
	UpdateEdgeWeight(id uuid.UUID, weight float64) error
	TraverseBFSFromChunk(startChunkID uuid.UUID, maxDepth int, edgeType *model.EdgeType) ([]*model.TraversalNode, error)
}

EdgesDBHandlerFunctions defines the interface for Edges database operations.

type EntitiesDBHandler

type EntitiesDBHandler struct {
	// contains filtered or unexported fields
}

EntitiesDBHandler handles entity-related database operations

func NewEntitiesDBHandler

func NewEntitiesDBHandler(db *helper.Database, force bool) (*EntitiesDBHandler, error)

NewEntitiesDBHandler creates a new entities database handler. It initializes the database connection and loads entity-related SQL functions. If force is true, it will reload the SQL functions even if they already exist.

func (*EntitiesDBHandler) CreateTable

func (h *EntitiesDBHandler) CreateTable() error

CreateTable creates the 'entities' table in the database. If the table already exists, it does not create it again. It also creates all necessary indexes.

func (*EntitiesDBHandler) DeleteEntity

func (h *EntitiesDBHandler) DeleteEntity(id uuid.UUID) error

DeleteEntity deletes an entity by ID

func (*EntitiesDBHandler) GetChunksForEntity

func (h *EntitiesDBHandler) GetChunksForEntity(ctx context.Context, entityID string) ([]*model.Chunk, error)

GetChunksForEntity retrieves all chunks related to an entity

func (*EntitiesDBHandler) GetEntity

func (h *EntitiesDBHandler) GetEntity(ctx context.Context, id string) (*model.Entity, error)

GetEntity retrieves an entity by ID (alias for SelectEntity for interface compatibility)

func (*EntitiesDBHandler) InsertEntity

func (h *EntitiesDBHandler) InsertEntity(entity *model.Entity) error

InsertEntity inserts a new entity (or updates if exists)

func (*EntitiesDBHandler) SelectChunksMentioningEntity

func (h *EntitiesDBHandler) SelectChunksMentioningEntity(entityID uuid.UUID) ([]*model.ChunkMention, error)

SelectChunksMentioningEntity retrieves chunks that mention an entity

func (*EntitiesDBHandler) SelectEntitiesBySearch

func (h *EntitiesDBHandler) SelectEntitiesBySearch(searchTerm string, entityType *string, limit int) ([]*model.Entity, error)

SelectEntitiesBySearch searches entities by name pattern

func (*EntitiesDBHandler) SelectEntitiesByType

func (h *EntitiesDBHandler) SelectEntitiesByType(entityType string, limit int) ([]*model.Entity, error)

SelectEntitiesByType retrieves entities by type

func (*EntitiesDBHandler) SelectEntity

func (h *EntitiesDBHandler) SelectEntity(id uuid.UUID) (*model.Entity, error)

SelectEntity retrieves an entity by ID

func (*EntitiesDBHandler) SelectEntityByName

func (h *EntitiesDBHandler) SelectEntityByName(name string, entityType string) (*model.Entity, error)

SelectEntityByName retrieves an entity by name and type

func (*EntitiesDBHandler) UpdateEntityMetadata

func (h *EntitiesDBHandler) UpdateEntityMetadata(id uuid.UUID, metadata model.Metadata) error

UpdateEntityMetadata updates the metadata of an entity

type EntitiesDBHandlerFunctions

type EntitiesDBHandlerFunctions interface {
	InsertEntity(entity *model.Entity) error
	SelectEntity(id uuid.UUID) (*model.Entity, error)
	SelectEntityByName(name string, entityType string) (*model.Entity, error)
	SelectEntitiesBySearch(searchTerm string, entityType *string, limit int) ([]*model.Entity, error)
	SelectEntitiesByType(entityType string, limit int) ([]*model.Entity, error)
	DeleteEntity(id uuid.UUID) error
	UpdateEntityMetadata(id uuid.UUID, metadata map[string]interface{}) error
	SelectChunksMentioningEntity(entityID uuid.UUID) ([]*model.ChunkMention, error)
}

EntitiesDBHandlerFunctions defines the interface for Entities database operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL