{"modulePath":"github.com/OpenSIN-Code/SIN-Code-Bundle","version":"v1.7.3","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package memory\n\nSPDX-License-Identifier: MIT Purpose: text embedding via NVIDIA NIM. Uses nv-embed-v1 (or any OpenAI-compatible /v1/embeddings endpoint).\n\nSPDX-License-Identifier: MIT Purpose: long-term project memory — bbolt-backed knowledge store with semantic search via NIM embeddings. Inspired by beads (gastownhall/beads).\n\nSPDX-License-Identifier: MIT Purpose: semantic search, knowledge graph traversal, and prime-context injection for agents. All in-memory over the Store.\n\nSPDX-License-Identifier: MIT Purpose: bbolt-backed Memory store with embeddings, links, and append-only audit log. Embeddings are cached in-memory by text hash.\n\n## Constants\n\n```go\nconst NIMEmbedBaseURL = \"https://integrate.api.nvidia.com/v1\"\n```\n\n```go\nconst NIMEmbedModel = \"nvidia/nv-embed-v1\"\n```\n\n## Variables\n\n```go\nvar (\n\tErrNotFound = errors.New(\"memory: not found\")\n)\n```\n\n```go\nvar ValidLinkTypes = []LinkType{LinkReferences, LinkSupports, LinkContradicts, LinkExtends, LinkCauses}\n```\n\n## Functions\n\n```go\nfunc CosineSimilarity(a, b []float32) float64\n```\n\n```go\nfunc GenerateID(insight string) string\n```\n\n```go\nfunc NoopEmbedding(text string) ([]float32, error)\n```\nNoopEmbedding returns an empty vector — used when no embedder is configured.\n\n```go\nfunc NormalizeTags(tags []string) []string\n```\n\n```go\nfunc SetEmbedder(fn EmbeddingFunc, dim int)\n```\n\n```go\nfunc SetupNIMEmbedder()\n```\nSetupNIMEmbedder registers the NIM embedder as the default.\n\n## Types\n\n```go\ntype EmbedRequest struct {\n\tInput []string `json:\"input\"`\n\tModel string   `json:\"model\"`\n}\n```\n\n```go\ntype EmbedResponse struct {\n\tData []struct {\n\t\tEmbedding []float32 `json:\"embedding\"`\n\t\tIndex     int       `json:\"index\"`\n\t} `json:\"data\"`\n\tUsage struct {\n\t\tPromptTokens int `json:\"prompt_tokens\"`\n\t\tTotalTokens  int `json:\"total_tokens\"`\n\t} `json:\"usage\"`\n}\n```\n\n```go\ntype Embedder struct {\n\tBaseURL string\n\tModel   string\n\tAPIKey  string\n\tHTTP    *http.Client\n}\n```\n\n```go\nfunc NewNIMEmbedder() *Embedder\n```\n\n```go\nfunc (e *Embedder) Embed(ctx context.Context, texts []string) ([][]float32, error)\n```\n\n```go\nfunc (e *Embedder) EmbedOne(ctx context.Context, text string) ([]float32, error)\n```\n\n```go\ntype EmbeddingFunc func(text string) ([]float32, error)\n```\n\n```go\nfunc GetEmbedder() (EmbeddingFunc, int)\n```\n\n```go\ntype Link struct {\n\tFrom    string    `json:\"from\"`\n\tTo      string    `json:\"to\"`\n\tRel     string    `json:\"rel\"`\n\tCreated time.Time `json:\"created\"`\n}\n```\n\n```go\ntype LinkType string\n```\n\n```go\nconst (\n\tLinkReferences  LinkType = \"references\"\n\tLinkSupports    LinkType = \"supports\"\n\tLinkContradicts LinkType = \"contradicts\"\n\tLinkExtends     LinkType = \"extends\"\n\tLinkCauses      LinkType = \"causes\"\n)\n```\n\n```go\nfunc (l LinkType) Valid() bool\n```\n\n```go\ntype ListFilter struct {\n\tProject string\n\tTag     string\n\tTagsAny []string\n\tTagsAll []string\n\tActor   string\n\tSearch  string\n\tLimit   int\n}\n```\n\n```go\ntype Memory struct {\n\tID        string    `json:\"id\"`\n\tInsight   string    `json:\"insight\"`\n\tProject   string    `json:\"project,omitempty\"`\n\tTags      []string  `json:\"tags,omitempty\"`\n\tActor     string    `json:\"actor,omitempty\"`\n\tCreated   time.Time `json:\"created\"`\n\tUpdated   time.Time `json:\"updated\"`\n\tEmbedding []float32 `json:\"-\"`\n}\n```\n\n```go\ntype ScoredMemory struct {\n\t*Memory\n\tScore float64\n}\n```\n\n```go\ntype Store struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc Open(path string) (*Store, error)\n```\n\n```go\nfunc (s *Store) Add(m *Memory) error\n```\n\n```go\nfunc (s *Store) AddLink(l Link) error\n```\n\n```go\nfunc (s *Store) Close() error\n```\n\n```go\nfunc (s *Store) Delete(id string, hard bool) error\n```\n\n```go\nfunc (s *Store) EmbeddingStatus() (bool, int)\n```\n\n```go\nfunc (s *Store) Get(id string) (*Memory, error)\n```\n\n```go\nfunc (s *Store) GetLinks(id string) ([]Link, error)\n```\n\n```go\nfunc (s *Store) Graph(rootID string, maxDepth int) (map[string][]Link, error)\n```\nGraph traverses the knowledge graph from a starting node, returning all reachable nodes within maxDepth hops.\n\n```go\nfunc (s *Store) List(f ListFilter) ([]*Memory, error)\n```\n\n```go\nfunc (s *Store) Path() string\n```\n\n```go\nfunc (s *Store) Prime(query string, project string, topK int) (string, error)\n```\nPrime builds a context string with the top-K most relevant memories for the given query, formatted for injection into an LLM prompt.\n\n```go\nfunc (s *Store) RemoveLink(from, to string) error\n```\n\n```go\nfunc (s *Store) Search(query string, project string, limit int) ([]ScoredMemory, error)\n```\nSearch returns memories ranked by similarity to query. If the embedder is configured and the query embeds, uses cosine similarity over stored embeddings. Falls back to substring search.\n\n```go\nfunc (s *Store) Stats() (map[string]int, error)\n```\n\n","path":"github.com/OpenSIN-Code/SIN-Code-Bundle/cmd/sin-code/internal/memory","name":"memory","synopsis":"SPDX-License-Identifier: MIT Purpose: text embedding via NVIDIA NIM.","isRedistributable":true}
