Documentation
¶
Index ¶
- Variables
- func Similarity(a, b []float64) float64
- type Chunk
- type Document
- type Grokker
- func (g *Grokker) AbsPath(doc *Document) string
- func (g *Grokker) AddDocument(path string) (err error)
- func (g *Grokker) Answer(question string, global bool) (resp oai.ChatCompletionResponse, query string, err error)
- func (g *Grokker) CodeVersion() string
- func (g *Grokker) CreateEmbeddings(texts []string) (embeddings [][]float64, err error)
- func (g *Grokker) DBVersion() string
- func (g *Grokker) FindChunks(query string, K int) (chunks []*Chunk, err error)
- func (g *Grokker) ForgetDocument(path string) (err error)
- func (g *Grokker) GC() (err error)
- func (g *Grokker) Generate(question, ctxt string, global bool) (resp oai.ChatCompletionResponse, query string, err error)
- func (g *Grokker) GitCommitMessage(diff string) (resp oai.ChatCompletionResponse, query string, err error)
- func (g *Grokker) ListDocuments() (paths []string)
- func (g *Grokker) ListModels() (models []*Model, err error)
- func (g *Grokker) Migrate() (was, now string, err error)
- func (g *Grokker) RefreshEmbeddings() (err error)
- func (g *Grokker) Save(w io.Writer) (err error)
- func (g *Grokker) SimilarChunks(embedding []float64, K int) (chunks []*Chunk)
- func (g *Grokker) UpdateDocument(doc *Document) (updated bool, err error)
- func (g *Grokker) UpdateEmbeddings(lastUpdate time.Time) (update bool, err error)
- func (g *Grokker) UpgradeModel(model string) (err error)
- type Model
- type Models
Constants ¶
This section is empty.
Variables ¶
var DefaultModel = "gpt-3.5-turbo"
var GitCommitPrompt = `` /* 191-byte string literal not displayed */
var GitDiffPrompt = `` /* 181-byte string literal not displayed */
Functions ¶
func Similarity ¶
Similarity returns the cosine similarity between two embeddings.
Types ¶
type Chunk ¶
type Chunk struct { // The document that this chunk is from. // XXX this is redundant; we could just use the document's path. // XXX a chunk should be able to be from multiple documents. Document *Document // The text of the chunk. Text string // The embedding of the chunk. Embedding []float64 }
Chunk is a single chunk of text from a document.
type Document ¶
type Document struct { // XXX deprecated because we weren't precise about what it meant. Path string // The path to the document file, relative to g.Root RelPath string }
Document is a single document in a document repository.
type Grokker ¶
type Grokker struct { // The grokker version number this db was last updated with. Version string // The absolute path of the root directory of the document // repository. This is passed in from cli based on where we // found the db. Root string // The list of documents in the database. Documents []*Document // The list of chunks in the database. Chunks []*Chunk Model string // contains filtered or unexported fields }
func Load ¶
Load loads a Grokker database from an io.Reader. The grokpath argument is the absolute path of the grok file. XXX rename this to LoadFile, don't pass in the reader.
func (*Grokker) AddDocument ¶
AddDocument adds a document to the Grokker database. It creates the embeddings for the document and adds them to the database.
func (*Grokker) Answer ¶
func (g *Grokker) Answer(question string, global bool) (resp oai.ChatCompletionResponse, query string, err error)
Answer returns the answer to a question.
func (*Grokker) CodeVersion ¶ added in v1.1.1
CodeVersion returns the version of grokker.
func (*Grokker) CreateEmbeddings ¶
Embeddings returns the embeddings for a slice of text chunks.
func (*Grokker) FindChunks ¶
FindChunks returns the K most relevant chunks for a query.
func (*Grokker) ForgetDocument ¶ added in v1.1.1
ForgetDocument removes a document from the Grokker database.
func (*Grokker) Generate ¶
func (g *Grokker) Generate(question, ctxt string, global bool) (resp oai.ChatCompletionResponse, query string, err error)
Generate returns the answer to a question.
func (*Grokker) GitCommitMessage ¶
func (g *Grokker) GitCommitMessage(diff string) (resp oai.ChatCompletionResponse, query string, err error)
GitCommitMessage generates a git commit message given a diff. It appends a reasonable prompt, and then uses the result as a grokker query.
func (*Grokker) ListDocuments ¶ added in v1.1.1
ListDocuments returns a list of all documents in the knowledge base. XXX this is a bit of a hack, since we're using the document name as the document ID. XXX this is also a bit of a hack since we're trying to make this work for multiple versions
func (*Grokker) ListModels ¶
ListModels lists the available models.
func (*Grokker) Migrate ¶ added in v1.1.1
Migrate migrates the current Grokker database from an older version to the current version. XXX unexport this and call it from Load() after moving file ops into this package.
func (*Grokker) RefreshEmbeddings ¶
RefreshEmbeddings refreshes the embeddings for all documents in the database.
func (*Grokker) SimilarChunks ¶
SimilarChunks returns the K most similar chunks to an embedding. If K is 0, it returns all chunks.
func (*Grokker) UpdateDocument ¶
UpdateDocument updates the embeddings for a document and returns true if the document was updated.
func (*Grokker) UpdateEmbeddings ¶
UpdateEmbeddings updates the embeddings for any documents that have changed since the last time the embeddings were updated. It returns true if any embeddings were updated.
func (*Grokker) UpgradeModel ¶
UpgradeModel upgrades the model for a Grokker database.