store

package
v0.0.0-beta.30 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

func DecodeVector

func DecodeVector(b []byte) []float32

func EncodeVector

func EncodeVector(v []float32) []byte

Types

type Chunk

type Chunk struct {
	ID         string
	DocID      string
	ChunkIndex int
	Content    string
	TokenCount int
	Metadata   string
}

type ChunkWithEmbedding

type ChunkWithEmbedding struct {
	Chunk  Chunk
	Vector []float32
}

type Claim

type Claim struct {
	ID       string
	EntityID string
	Claim    string
	Status   string
	DocID    string
}

type Community

type Community struct {
	ID       string    `json:"id"`
	Level    int       `json:"level"`
	ParentID string    `json:"parent_id,omitempty"`
	Title    string    `json:"title,omitempty"`
	Summary  string    `json:"summary,omitempty"`
	Rank     int       `json:"rank"`
	Vector   []float32 `json:"vector,omitempty"`
}

type Document

type Document struct {
	ID          string `json:"id"`
	Path        string `json:"path"`
	Title       string `json:"title"`
	DocType     string `json:"doc_type"`
	FileHash    string `json:"file_hash,omitempty"`
	Structured  string `json:"structured,omitempty"`
	Version     int    `json:"version,omitempty"`
	CanonicalID string `json:"canonical_id,omitempty"` // empty on v1; ID of first version on v2+
	IsLatest    bool   `json:"is_latest,omitempty"`
	CreatedAt   int64  `json:"created_at"`
	UpdatedAt   int64  `json:"updated_at"`
}

func (*Document) CanonicalOrID

func (d *Document) CanonicalOrID() string

CanonicalOrID returns CanonicalID if set, otherwise the document's own ID. This is the stable identifier across all versions of a file.

type Entity

type Entity struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Type        string    `json:"type,omitempty"`
	Description string    `json:"description,omitempty"`
	Rank        int       `json:"rank"`
	CommunityID string    `json:"community_id,omitempty"`
	Vector      []float32 `json:"vector,omitempty"`
}

type Relationship

type Relationship struct {
	ID          string  `json:"id"`
	SourceID    string  `json:"source_id"`
	TargetID    string  `json:"target_id"`
	Predicate   string  `json:"predicate"`
	Description string  `json:"description,omitempty"`
	Weight      float64 `json:"weight"`
	DocID       string  `json:"doc_id"`
}

type Stats

type Stats struct {
	Documents     int `json:"documents"`
	Chunks        int `json:"chunks"`
	Embeddings    int `json:"embeddings"`
	Entities      int `json:"entities"`
	Relationships int `json:"relationships"`
	Claims        int `json:"claims"`
	Communities   int `json:"communities"`
}

type Store

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

Store wraps the single SQLite database.

func Open

func Open(path string) (*Store, error)

Open opens (or creates) the SQLite database at path and runs migrations.

func (*Store) AllChunkEmbeddings

func (s *Store) AllChunkEmbeddings(ctx context.Context, model string) ([]ChunkWithEmbedding, error)

func (*Store) AllCommunities

func (s *Store) AllCommunities(ctx context.Context) ([]*Community, error)

func (*Store) AllEntities

func (s *Store) AllEntities(ctx context.Context) ([]*Entity, error)

func (*Store) AllRelationships

func (s *Store) AllRelationships(ctx context.Context) ([]*Relationship, error)

func (*Store) BatchInsertChunks

func (s *Store) BatchInsertChunks(ctx context.Context, chunks []*Chunk) error

BatchInsertChunks inserts multiple chunks in one transaction.

func (*Store) BatchInsertClaims

func (s *Store) BatchInsertClaims(ctx context.Context, claims []*Claim) error

BatchInsertClaims inserts multiple claims in one transaction.

func (*Store) BatchInsertCommunityMembers

func (s *Store) BatchInsertCommunityMembers(ctx context.Context, communityID string, entityIDs []string) error

BatchInsertCommunityMembers inserts community memberships in one transaction.

func (*Store) BatchInsertRelationships

func (s *Store) BatchInsertRelationships(ctx context.Context, rels []*Relationship) error

BatchInsertRelationships inserts multiple relationships in one transaction.

func (*Store) BatchUpdateEntityCommunities

func (s *Store) BatchUpdateEntityCommunities(ctx context.Context, assignments map[string]string) error

BatchUpdateEntityCommunities updates community_id for multiple entities in one transaction.

func (*Store) BatchUpdateEntityRanks

func (s *Store) BatchUpdateEntityRanks(ctx context.Context, ranks map[string]int) error

BatchUpdateEntityRanks updates rank for multiple entities in one transaction.

func (*Store) BatchUpsertEmbeddings

func (s *Store) BatchUpsertEmbeddings(ctx context.Context, model string, chunkIDs []string, vectors [][]float32) error

BatchUpsertEmbeddings upserts multiple embeddings in one transaction.

func (*Store) BatchUpsertEntities

func (s *Store) BatchUpsertEntities(ctx context.Context, entities []*Entity) error

BatchUpsertEntities upserts multiple entities in one transaction.

func (*Store) ClearCommunities

func (s *Store) ClearCommunities(ctx context.Context) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) CommunityMembers

func (s *Store) CommunityMembers(ctx context.Context, communityID string) ([]*Entity, error)

func (*Store) DB

func (s *Store) DB() *sql.DB

func (*Store) FindRelationships

func (s *Store) FindRelationships(ctx context.Context, fromID, toID, predicate string) ([]*Relationship, error)

func (*Store) GetChunk

func (s *Store) GetChunk(ctx context.Context, id string) (*Chunk, error)

func (*Store) GetCommunity

func (s *Store) GetCommunity(ctx context.Context, id string) (*Community, error)

func (*Store) GetDocument

func (s *Store) GetDocument(ctx context.Context, id string) (*Document, error)

func (*Store) GetDocumentByHash

func (s *Store) GetDocumentByHash(ctx context.Context, hash string) (*Document, error)

func (*Store) GetDocumentByPath

func (s *Store) GetDocumentByPath(ctx context.Context, path string) (*Document, error)

func (*Store) GetDocumentVersions

func (s *Store) GetDocumentVersions(ctx context.Context, canonicalID string) ([]*Document, error)

GetDocumentVersions returns all versions of a document by canonical ID, oldest first.

func (*Store) GetEntitiesByNames

func (s *Store) GetEntitiesByNames(ctx context.Context, names []string) (map[string]*Entity, error)

GetEntitiesByNames fetches entities for a set of names in one query. Returns map name→Entity.

func (*Store) GetEntity

func (s *Store) GetEntity(ctx context.Context, id string) (*Entity, error)

func (*Store) GetEntityByName

func (s *Store) GetEntityByName(ctx context.Context, name string) (*Entity, error)

func (*Store) GetStats

func (s *Store) GetStats(ctx context.Context) (*Stats, error)

func (*Store) GraphFingerprint

func (s *Store) GraphFingerprint(ctx context.Context) (entities, relationships, communities int, err error)

GraphFingerprint returns counts of entities, relationships, and communities to detect whether the graph has changed since last finalization.

func (*Store) InsertChunk

func (s *Store) InsertChunk(ctx context.Context, c *Chunk) error

func (*Store) InsertClaim

func (s *Store) InsertClaim(ctx context.Context, c *Claim) error

func (*Store) InsertCommunityMember

func (s *Store) InsertCommunityMember(ctx context.Context, communityID, entityID string) error

func (*Store) InsertRelationship

func (s *Store) InsertRelationship(ctx context.Context, r *Relationship) error

func (*Store) ListChunksByDoc

func (s *Store) ListChunksByDoc(ctx context.Context, docID string) ([]*Chunk, error)

func (*Store) ListCommunities

func (s *Store) ListCommunities(ctx context.Context, level int) ([]*Community, error)

func (*Store) ListDocuments

func (s *Store) ListDocuments(ctx context.Context, docType string, limit, offset int) ([]*Document, error)

func (*Store) ListEntities

func (s *Store) ListEntities(ctx context.Context, typ string, limit, offset int) ([]*Entity, error)

func (*Store) RelationshipsForEntity

func (s *Store) RelationshipsForEntity(ctx context.Context, entityID string, depth int) ([]*Relationship, error)

func (*Store) SupersedeDocument

func (s *Store) SupersedeDocument(ctx context.Context, id string) error

SupersedeDocument marks a document as no longer the latest version.

func (*Store) UpdateDocumentStructured

func (s *Store) UpdateDocumentStructured(ctx context.Context, id, structured string) error

func (*Store) UpdateEntityCommunity

func (s *Store) UpdateEntityCommunity(ctx context.Context, entityID, communityID string) error

func (*Store) UpdateEntityRank

func (s *Store) UpdateEntityRank(ctx context.Context, entityID string, rank int) error

func (*Store) UpsertCommunity

func (s *Store) UpsertCommunity(ctx context.Context, c *Community) error

func (*Store) UpsertDocument

func (s *Store) UpsertDocument(ctx context.Context, doc *Document) error

func (*Store) UpsertEmbedding

func (s *Store) UpsertEmbedding(ctx context.Context, chunkID, model string, vector []float32) error

func (*Store) UpsertEntity

func (s *Store) UpsertEntity(ctx context.Context, e *Entity) error

Jump to

Keyboard shortcuts

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