vector

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDocsAsContext

func FormatDocsAsContext(docsJSON string) (string, error)

FormatDocsAsContext is a utility to format a JSON list of documents into a readable context string. This is typically used to inject retrieved knowledge into an LLM prompt.

Parameters:

  • docsJSON: The JSON string returned by RetrieverAction.Execute.

Returns:

  • A formatted string (e.g., "Document 1...\nDocument 2...").

func NewGenkitRetrieverAction

func NewGenkitRetrieverAction(name string, retriever ai.Retriever, embedder ai.Embedder) core.Action

NewGenkitRetrieverAction creates a protected core.Action from a Genkit ai.Retriever.

Parameters:

  • name: The unique name for this action.
  • retriever: The Genkit retriever instance.
  • embedder: Optional embedder (if required by the retriever).

Returns:

  • A core.Action that can be used with `client.Protect()`.

Types

type Document

type Document struct {
	// Content is the textual body of the document.
	Content string `json:"content"`
	// Source indicates the origin of the document (e.g., filename, URL).
	Source string `json:"source"`
}

Document represents a single unit of retrieved knowledge.

type DocumentRetriever

type DocumentRetriever interface {
	// Retrieve finds semantically similar documents for a given query.
	//
	// Parameters:
	//   - ctx: The execution context.
	//   - query: The search string.
	//
	// Returns:
	//   - A slice of Document matches, or an error.
	Retrieve(ctx context.Context, query string) ([]Document, error)
}

DocumentRetriever defines the interface for a vector search backend. It abstracts the underlying storage mechanism (Pinecone, Weaviate, Local).

type GenkitRetriever

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

GenkitRetriever adapts the Genkit ai.Retriever interface to the Manglekit DocumentRetriever interface. It acts as a bridge, allowing Manglekit to use any retriever plugin compatible with Genkit (e.g., Pinecone, Chroma).

func NewGenkitRetriever

func NewGenkitRetriever(retriever ai.Retriever, embedder ai.Embedder) *GenkitRetriever

NewGenkitRetriever initializes a new adapter for a Genkit retriever.

Parameters:

  • retriever: The Genkit retriever instance.
  • embedder: An optional embedder. If the retriever handles embeddings internally, this can be nil.

Returns:

  • A pointer to the initialized GenkitRetriever.

func (*GenkitRetriever) Retrieve

func (gr *GenkitRetriever) Retrieve(ctx context.Context, query string) ([]Document, error)

Retrieve executes a search query against the underlying Genkit retriever. It converts the results into Manglekit's standard Document format.

Parameters:

  • ctx: The execution context.
  • query: The search query string.

Returns:

  • A slice of Document structs found by the retriever.

type RetrieverAction

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

RetrieverAction wraps a DocumentRetriever into a core.Action. This allows retrieval operations to be governed by policies and traced.

func NewRetrieverAction

func NewRetrieverAction(name string, retriever DocumentRetriever) *RetrieverAction

NewRetrieverAction creates a new RetrieverAction.

Parameters:

  • name: The unique name for this action.
  • retriever: The retrieval backend implementation.

Returns:

  • A pointer to the initialized RetrieverAction.

func (*RetrieverAction) Execute

func (r *RetrieverAction) Execute(ctx context.Context, input core.Envelope) (core.Envelope, error)

Execute performs the vector search. It expects a string payload (query) and returns a JSON string payload (list of documents).

Parameters:

  • ctx: The execution context.
  • input: The input Envelope (Payload must be string).

Returns:

  • A result Envelope containing a JSON string of retrieved documents.

func (*RetrieverAction) Metadata

func (r *RetrieverAction) Metadata() core.ActionMetadata

Metadata returns the action's metadata.

type SimpleStore

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

SimpleStore is a thread-safe, in-memory vector store using Cosine Similarity. For <10k items, this is faster than HNSW overhead.

func NewSimpleStore

func NewSimpleStore(embedder core.Embedder) *SimpleStore

func (*SimpleStore) Get

func (s *SimpleStore) Get(ctx context.Context, id string) (string, error)

func (*SimpleStore) Search

func (s *SimpleStore) Search(ctx context.Context, query string, topK int) ([]string, error)

func (*SimpleStore) Upsert

func (s *SimpleStore) Upsert(ctx context.Context, id string, content string) error

Jump to

Keyboard shortcuts

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