knowledge

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package knowledge builds and serves the read-only knowledge representation of an M-Press site. The artifact is deterministic and contains no credentials or authoring controls.

Index

Constants

View Source
const (
	Schema       = 2
	Directory    = "knowledge"
	ManifestFile = "manifest.json"
	PagesFile    = "pages.json"
	ChunksFile   = "chunks.json"
	IndexFile    = "index.json"
)

Variables

This section is empty.

Functions

func Generate

func Generate(output string, cfg config.Config, pagesByLanguage map[string][]*content.Page) error

Generate writes the complete portable knowledge bundle beneath output.

func HTTPHandler

func HTTPHandler(store *Store, version string) http.Handler

func NewMCPServer

func NewMCPServer(store *Store, version string) *mcp.Server

NewMCPServer creates a read-only server over one verified build artifact. It intentionally shares no handlers with the development authoring server.

func RunStdio

func RunStdio(ctx context.Context, store *Store, version string) error

Types

type Artifacts

type Artifacts struct {
	Pages  string `json:"pages"`
	Chunks string `json:"chunks"`
	Index  string `json:"index"`
}

type Chunk

type Chunk struct {
	ID          string   `json:"id"`
	PageID      string   `json:"pageId"`
	ResourceURI string   `json:"resourceUri"`
	Language    string   `json:"language"`
	Version     string   `json:"version"`
	Route       string   `json:"route"`
	URL         string   `json:"url"`
	Source      string   `json:"source"`
	PageTitle   string   `json:"pageTitle"`
	Title       string   `json:"title"`
	HeadingID   string   `json:"headingId,omitempty"`
	HeadingPath []string `json:"headingPath,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Part        int      `json:"part,omitempty"`
	Text        string   `json:"text"`
}

type EvaluationCase

type EvaluationCase struct {
	ID             string   `json:"id"`
	Query          string   `json:"query"`
	Language       string   `json:"language,omitempty"`
	Version        string   `json:"version,omitempty"`
	Tags           []string `json:"tags,omitempty"`
	ExpectedRoutes []string `json:"expectedRoutes"`
}

type EvaluationReport

type EvaluationReport struct {
	Suite        string             `json:"suite"`
	Cases        int                `json:"cases"`
	Passed       int                `json:"passed"`
	RecallAt1    float64            `json:"recallAt1"`
	RecallAt3    float64            `json:"recallAt3"`
	RecallAt5    float64            `json:"recallAt5"`
	MRR          float64            `json:"mrr"`
	CitationRate float64            `json:"citationRate"`
	Results      []EvaluationResult `json:"results"`
}

type EvaluationResult

type EvaluationResult struct {
	ID             string   `json:"id"`
	Query          string   `json:"query"`
	Passed         bool     `json:"passed"`
	Rank           int      `json:"rank,omitempty"`
	ExpectedRoutes []string `json:"expectedRoutes"`
	TopURLs        []string `json:"topUrls,omitempty"`
}

type EvaluationSuite

type EvaluationSuite struct {
	Name  string           `json:"name"`
	Cases []EvaluationCase `json:"cases"`
}

func LoadEvaluationSuite

func LoadEvaluationSuite(path string) (EvaluationSuite, error)

type GetPageInput

type GetPageInput struct {
	ID  string `json:"id,omitempty" jsonschema:"Page ID returned by search or resources/list."`
	URL string `json:"url,omitempty" jsonschema:"Canonical URL or route of the page."`
}

type GetPageOutput

type GetPageOutput struct {
	ID          string   `json:"id"`
	ResourceURI string   `json:"resourceUri"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	URL         string   `json:"url"`
	Language    string   `json:"language"`
	Version     string   `json:"version"`
	Tags        []string `json:"tags,omitempty"`
	Text        string   `json:"text"`
}

type Index

type Index struct {
	Schema int         `json:"schema"`
	Terms  []IndexTerm `json:"terms"`
}

type IndexTerm

type IndexTerm struct {
	Term     string    `json:"term"`
	Postings []Posting `json:"postings"`
}

type Manifest

type Manifest struct {
	Schema          int           `json:"schema"`
	Title           string        `json:"title"`
	Description     string        `json:"description,omitempty"`
	BaseURL         string        `json:"baseUrl,omitempty"`
	DefaultLanguage string        `json:"defaultLanguage"`
	Languages       []string      `json:"languages"`
	CurrentVersion  string        `json:"currentVersion"`
	Digest          string        `json:"digest"`
	Pages           []PageSummary `json:"pages"`
	Artifacts       Artifacts     `json:"artifacts"`
}

type Page

type Page struct {
	PageSummary
	Text string `json:"text"`
}

type PageSummary

type PageSummary struct {
	ID          string   `json:"id"`
	ResourceURI string   `json:"resourceUri"`
	Language    string   `json:"language"`
	Version     string   `json:"version"`
	Route       string   `json:"route"`
	URL         string   `json:"url"`
	Source      string   `json:"source"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	ChunkCount  int      `json:"chunkCount"`
}

type Posting

type Posting struct {
	ChunkID string `json:"chunkId"`
	Text    int    `json:"text,omitempty"`
	Page    int    `json:"page,omitempty"`
	Title   int    `json:"title,omitempty"`
	Route   int    `json:"route,omitempty"`
	Tags    int    `json:"tags,omitempty"`
}

type SearchInput

type SearchInput struct {
	Query    string   `json:"query" jsonschema:"Words or exact phrase to find in the knowledge base."`
	Language string   `json:"language,omitempty" jsonschema:"Optional language code such as en or fr."`
	Version  string   `json:"version,omitempty" jsonschema:"Optional documentation version. Defaults to the current version."`
	Tags     []string `json:"tags,omitempty" jsonschema:"Optional tags that every result must contain."`
	Limit    int      `json:"limit,omitempty" jsonschema:"Maximum results from 1 to 50. Defaults to 8."`
}

type SearchOptions

type SearchOptions struct {
	Query    string   `json:"query"`
	Language string   `json:"language,omitempty"`
	Version  string   `json:"version,omitempty"`
	Tags     []string `json:"tags,omitempty"`
	Limit    int      `json:"limit,omitempty"`
}

type SearchOutput

type SearchOutput struct {
	Query   string         `json:"query"`
	Results []SearchResult `json:"results"`
}

type SearchResult

type SearchResult struct {
	ChunkID      string   `json:"chunkId"`
	PageID       string   `json:"pageId"`
	ResourceURI  string   `json:"resourceUri"`
	PageResource string   `json:"pageResource"`
	Title        string   `json:"title"`
	PageTitle    string   `json:"pageTitle"`
	URL          string   `json:"url"`
	Language     string   `json:"language"`
	Version      string   `json:"version"`
	HeadingPath  []string `json:"headingPath,omitempty"`
	Snippet      string   `json:"snippet"`
	Score        int      `json:"score"`
}

type SiteInfo

type SiteInfo struct {
	Title           string   `json:"title"`
	Description     string   `json:"description,omitempty"`
	BaseURL         string   `json:"baseUrl,omitempty"`
	DefaultLanguage string   `json:"defaultLanguage"`
	Languages       []string `json:"languages"`
	CurrentVersion  string   `json:"currentVersion"`
	Pages           int      `json:"pages"`
	Sections        int      `json:"sections"`
	Digest          string   `json:"digest"`
}

type Store

type Store struct {
	Manifest Manifest
	Pages    []Page
	Chunks   []Chunk
	// contains filtered or unexported fields
}

func Load

func Load(output string) (*Store, error)

Load reads and verifies a generated knowledge bundle.

func LoadAll

func LoadAll(output string) (*Store, error)

LoadAll loads the current artifact and any captured version artifacts mounted beneath the generated site. Mounted snapshots are relabelled in memory so version filters and resource identifiers cannot collide with the current corpus or with each other.

func (*Store) Chunk

func (s *Store) Chunk(id string) (*Chunk, bool)

func (*Store) Evaluate

func (s *Store) Evaluate(suite EvaluationSuite, limit int) EvaluationReport

func (*Store) Page

func (s *Store) Page(id string) (*Page, bool)

func (*Store) Search

func (s *Store) Search(options SearchOptions) []SearchResult

Jump to

Keyboard shortcuts

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