Documentation
¶
Index ¶
- func CosineSimilarity(a, b []float32) float32
- func DecodeVector(b []byte) []float32
- func EncodeVector(v []float32) []byte
- type Chunk
- type ChunkWithEmbedding
- type Claim
- type Community
- type Document
- type Entity
- type NoteHit
- type Relationship
- type Stats
- type Store
- func (s *Store) AllChunkEmbeddings(ctx context.Context, model string) ([]ChunkWithEmbedding, error)
- func (s *Store) AllCommunities(ctx context.Context) ([]*Community, error)
- func (s *Store) AllDocuments(ctx context.Context) ([]*Document, error)
- func (s *Store) AllEntities(ctx context.Context) ([]*Entity, error)
- func (s *Store) AllRelationships(ctx context.Context) ([]*Relationship, error)
- func (s *Store) BatchInsertChunks(ctx context.Context, chunks []*Chunk) error
- func (s *Store) BatchInsertClaims(ctx context.Context, claims []*Claim) error
- func (s *Store) BatchInsertCommunityMembers(ctx context.Context, communityID string, entityIDs []string) error
- func (s *Store) BatchInsertRelationships(ctx context.Context, rels []*Relationship) error
- func (s *Store) BatchUpdateEntityCommunities(ctx context.Context, assignments map[string]string) error
- func (s *Store) BatchUpdateEntityRanks(ctx context.Context, ranks map[string]int) error
- func (s *Store) BatchUpsertEmbeddings(ctx context.Context, model string, chunkIDs []string, vectors [][]float32) error
- func (s *Store) BatchUpsertEntities(ctx context.Context, entities []*Entity) error
- func (s *Store) ClaimsForEntity(ctx context.Context, entityID string) ([]*Claim, error)
- func (s *Store) ClearCommunities(ctx context.Context) error
- func (s *Store) Close() error
- func (s *Store) CommunityMembers(ctx context.Context, communityID string) ([]*Entity, error)
- func (s *Store) CountNotes(ctx context.Context) (int, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteDocument(ctx context.Context, id string) (int64, error)
- func (s *Store) DeleteNote(ctx context.Context, key string) error
- func (s *Store) FindRelationships(ctx context.Context, fromID, toID, predicate string) ([]*Relationship, error)
- func (s *Store) GetChunk(ctx context.Context, id string) (*Chunk, error)
- func (s *Store) GetCommunity(ctx context.Context, id string) (*Community, error)
- func (s *Store) GetDocument(ctx context.Context, id string) (*Document, error)
- func (s *Store) GetDocumentByHash(ctx context.Context, hash string) (*Document, error)
- func (s *Store) GetDocumentByPath(ctx context.Context, path string) (*Document, error)
- func (s *Store) GetDocumentVersions(ctx context.Context, canonicalID string) ([]*Document, error)
- func (s *Store) GetEntitiesByNames(ctx context.Context, names []string) (map[string]*Entity, error)
- func (s *Store) GetEntity(ctx context.Context, id string) (*Entity, error)
- func (s *Store) GetEntityByName(ctx context.Context, name string) (*Entity, error)
- func (s *Store) GetStats(ctx context.Context) (*Stats, error)
- func (s *Store) GraphFingerprint(ctx context.Context) (entities, relationships, communities int, err error)
- func (s *Store) IndexNote(ctx context.Context, n *notes.Note) error
- func (s *Store) InsertChunk(ctx context.Context, c *Chunk) error
- func (s *Store) InsertClaim(ctx context.Context, c *Claim) error
- func (s *Store) InsertCommunityMember(ctx context.Context, communityID, entityID string) error
- func (s *Store) InsertRelationship(ctx context.Context, r *Relationship) error
- func (s *Store) ListChunksByDoc(ctx context.Context, docID string) ([]*Chunk, error)
- func (s *Store) ListClaims(ctx context.Context, status string, limit int) ([]*Claim, error)
- func (s *Store) ListCommunities(ctx context.Context, level int) ([]*Community, error)
- func (s *Store) ListDocuments(ctx context.Context, docType string, limit, offset int) ([]*Document, error)
- func (s *Store) ListEntities(ctx context.Context, typ string, limit, offset int) ([]*Entity, error)
- func (s *Store) RelationshipsForEntity(ctx context.Context, entityID string, depth int) ([]*Relationship, error)
- func (s *Store) SearchNotes(ctx context.Context, query string, limit int) ([]NoteHit, error)
- func (s *Store) SupersedeDocument(ctx context.Context, id string) error
- func (s *Store) UpdateDocumentStructured(ctx context.Context, id, structured string) error
- func (s *Store) UpdateEntityCommunity(ctx context.Context, entityID, communityID string) error
- func (s *Store) UpdateEntityRank(ctx context.Context, entityID string, rank int) error
- func (s *Store) UpsertCommunity(ctx context.Context, c *Community) error
- func (s *Store) UpsertDocument(ctx context.Context, doc *Document) error
- func (s *Store) UpsertEmbedding(ctx context.Context, chunkID, model string, vector []float32) error
- func (s *Store) UpsertEntity(ctx context.Context, e *Entity) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosineSimilarity ¶
func DecodeVector ¶
func EncodeVector ¶
Types ¶
type ChunkWithEmbedding ¶
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"`
IndexedMtime int64 `json:"indexed_mtime,omitempty"` // Unix seconds mtime observed at index time
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
func (*Document) CanonicalOrID ¶
CanonicalOrID returns CanonicalID if set, otherwise the document's own ID. This is the stable identifier across all versions of a file.
type NoteHit ¶
type NoteHit struct {
Key string `json:"key"`
Title string `json:"title"`
Snippet string `json:"snippet"`
Tags []string `json:"tags,omitempty"`
Rank float64 `json:"rank"`
}
NoteHit is a single result from SearchNotes.
type Relationship ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the single SQLite database.
func OpenForProject ¶
OpenForProject opens (or creates) the SQLite DB for a single project at $dataDir/projects/<slug>/docscontext.db. The directory is created with 0o755 if missing. Validates slug against the canonical charset ([a-z0-9_-]+) so we never open a DB at a path the registry couldn't round-trip.
Callers that still need the flat legacy path can keep using Open(path); this function is additive.
func (*Store) AllChunkEmbeddings ¶
func (*Store) AllCommunities ¶
func (*Store) AllDocuments ¶
AllDocuments returns every row in the documents table regardless of is_latest or doc_type. Used by `docsiq index --prune` to scan for documents whose backing file has disappeared.
func (*Store) AllRelationships ¶
func (s *Store) AllRelationships(ctx context.Context) ([]*Relationship, error)
func (*Store) BatchInsertChunks ¶
BatchInsertChunks inserts multiple chunks in one transaction.
func (*Store) BatchInsertClaims ¶
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 ¶
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 ¶
BatchUpsertEntities upserts multiple entities in one transaction.
func (*Store) ClaimsForEntity ¶
ClaimsForEntity returns all claims attached to the given entity ID. Returns an empty slice (not nil) on no-match so JSON encoders emit `[]` rather than `null`.
func (*Store) CommunityMembers ¶
func (*Store) CountNotes ¶
CountNotes returns the row count of notes_fts.
func (*Store) DeleteDocument ¶
DeleteDocument hard-deletes a document row. ON DELETE CASCADE on chunks/embeddings/relationships takes care of dependent rows. Returns the number of rows removed so callers can distinguish "did nothing" from "did something."
func (*Store) DeleteNote ¶
DeleteNote removes a key from notes_fts. Not an error if the key is absent.
func (*Store) FindRelationships ¶
func (*Store) GetCommunity ¶
func (*Store) GetDocument ¶
func (*Store) GetDocumentByHash ¶
func (*Store) GetDocumentByPath ¶
func (*Store) GetDocumentVersions ¶
GetDocumentVersions returns all versions of a document by canonical ID, oldest first.
func (*Store) GetEntitiesByNames ¶
GetEntitiesByNames fetches entities for a set of names in one query. Returns map name→Entity.
func (*Store) GetEntityByName ¶
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) IndexNote ¶
IndexNote upserts a note into notes_fts. DELETE-by-key + INSERT is used instead of `INSERT ... ON CONFLICT` because the contentless FTS5 table has no declared primary key.
Tags are lowercased on index (decision: lowercase normalization so searches are case-insensitive). The title is derived from the last path segment of the key.
func (*Store) InsertCommunityMember ¶
func (*Store) InsertRelationship ¶
func (s *Store) InsertRelationship(ctx context.Context, r *Relationship) error
func (*Store) ListChunksByDoc ¶
func (*Store) ListClaims ¶
ListClaims returns claims, optionally filtered by status. A non-positive limit is clamped to 100; an upper bound of 1000 is enforced to keep a single request from pulling the whole table.
func (*Store) ListCommunities ¶
func (*Store) ListDocuments ¶
func (*Store) ListEntities ¶
func (*Store) RelationshipsForEntity ¶
func (*Store) SearchNotes ¶
SearchNotes runs a FTS5 MATCH query ranked by bm25() and returns up to `limit` hits with a highlighted snippet. `limit` <= 0 defaults to 20.
Empty / whitespace-only queries return an empty slice (no hits) rather than an error — callers can keep their code simple.
Special chars in `query` are escaped by wrapping each whitespace- delimited token in double quotes (FTS5 string literal syntax). This lets callers pass arbitrary user text including `:`, `*`, `"`, etc. without triggering a "malformed MATCH expression" error.
func (*Store) SupersedeDocument ¶
SupersedeDocument marks a document as no longer the latest version.