vector

package
v0.0.0-...-35c3f38 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

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.