RAG

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHATBOT_PROMPT_TEMPLATE = `` /* 917-byte string literal not displayed */

	AGENT_PROMPT_TEMPLATE = `` /* 3051-byte string literal not displayed */

	REPORT_PROMPT_TEMPLATE = `` /* 1216-byte string literal not displayed */

)
View Source
const (
	DEFAULT_TOP_K = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentResponse

type AgentResponse struct {
	Response      string  `json:"response"`
	SchemaChanges []Table `json:"schema_changes"`
	SchemaDDL     string  `json:"schema_ddl"`
}

type Analytic

type Analytic struct {
	DiskUsage    float64 `json:"DISK_USAGE"`
	CPUUsage     float64 `json:"CPU_USAGE"`
	MemoryUsage  float64 `json:"MEMORY_USAGE"`
	NetworkUsage float64 `json:"NETWORK_USAGE"`
	Costs        float64 `json:"COSTS"`
}

type Analytics

type Analytics struct {
	MonthlyAnalytics map[string]Analytic `json:"MONTHLY_ANALYTICS"`
}

type ChatbotResponse added in v1.0.1

type ChatbotResponse struct {
	ResponseText string   `json:"response_text"`
	Sources      []string `json:"sources"`
}

type CodeBlock added in v1.0.8

type CodeBlock struct {
	Language string `json:"language"`
	Code     string `json:"code"`
}

CodeBlock represents a code block extracted from markdown

type CodeExtractor added in v1.0.8

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

CodeExtractor handles extraction of code segments from markdown

func NewCodeExtractor added in v1.0.8

func NewCodeExtractor() *CodeExtractor

NewCodeExtractor creates a new CodeExtractor instance

func (*CodeExtractor) ExtractAllSegments added in v1.0.8

func (ce *CodeExtractor) ExtractAllSegments(markdownText string) ExtractedSegments

ExtractAllSegments extracts both JSON and SQL segments

func (*CodeExtractor) ExtractCodeBlocks added in v1.0.8

func (ce *CodeExtractor) ExtractCodeBlocks(markdownText string) []CodeBlock

ExtractCodeBlocks extracts all code blocks from markdown text

func (*CodeExtractor) ExtractInlineCode added in v1.0.8

func (ce *CodeExtractor) ExtractInlineCode(markdownText string) []string

ExtractInlineCode extracts inline code segments (text wrapped in backticks)

func (*CodeExtractor) ExtractJSONBlocks added in v1.0.8

func (ce *CodeExtractor) ExtractJSONBlocks(markdownText string) []JSONBlock

ExtractJSONBlocks extracts and parses JSON code blocks

func (*CodeExtractor) ExtractSQLBlocks added in v1.0.8

func (ce *CodeExtractor) ExtractSQLBlocks(markdownText string) []SQLBlock

ExtractSQLBlocks extracts SQL code blocks

func (*CodeExtractor) FilterCodeBlocksByLanguage added in v1.0.8

func (ce *CodeExtractor) FilterCodeBlocksByLanguage(codeBlocks []CodeBlock, languages []string) []CodeBlock

FilterCodeBlocksByLanguage filters code blocks by specific language

func (*CodeExtractor) PrettyPrintJSON added in v1.0.8

func (ce *CodeExtractor) PrettyPrintJSON(jsonStr string) (string, error)

PrettyPrintJSON formats JSON string with indentation

func (*CodeExtractor) ValidateJSON added in v1.0.8

func (ce *CodeExtractor) ValidateJSON(jsonStr string) error

ValidateJSON validates if a JSON string is valid

type ColumnInfo

type ColumnInfo struct {
	Type      string        `json:"TYPE"`
	Nullable  *bool         `json:"NULLABLE"`
	Unique    *bool         `json:"UNIQUE"`
	Default   interface{}   `json:"DEFAULT"`
	Checks    []interface{} `json:"CHECKS"`
	IsPrimary bool          `json:"IS_PRIMARY"`
	IsIndex   bool          `json:"IS_INDEX"`
	Comment   *string       `json:"COMMENT"`
}

type ConstraintInfo added in v1.0.7

type ConstraintInfo struct {
	TableName         string  `db:"table_name" json:"TableName"`
	ConstraintName    string  `db:"constraint_name" json:"ConstraintName"`
	ConstraintType    string  `db:"constraint_type" json:"ConstraintType"`
	ColumnName        *string `db:"column_name" json:"ColumnName"`
	ForeignTableName  *string `db:"foreign_table_name" json:"ForeignTableName"`
	ForeignColumnName *string `db:"foreign_column_name" json:"ForeignColumnName"`
	CheckClause       *string `db:"check_clause" json:"CheckClause"`
	OrdinalPosition   *int    `db:"ordinal_position" json:"OrdinalPosition"`
}

ConstraintInfo represents database constraints

type ExtractedSegments added in v1.0.8

type ExtractedSegments struct {
	JSONBlocks    []JSONBlock `json:"json_blocks"`
	SQLBlocks     []SQLBlock  `json:"sql_blocks"`
	AllCodeBlocks []CodeBlock `json:"all_code_blocks"`
}

ExtractedSegments contains all extracted code segments

type ForeignKeyInfo

type ForeignKeyInfo struct {
	Columns         []string `json:"COLUMNS"`
	ForeignTable    string   `json:"FOREIGN_TABLE"`
	ReferredColumns []string `json:"REFERRED_COLUMNS"`
	OnDelete        *string  `json:"ON_DELETE"`
	OnUpdate        *string  `json:"ON_UPDATE"`
}

type IndexInfo added in v1.0.7

type IndexInfo struct {
	TableName  string `db:"table_name" json:"TableName"`
	IndexName  string `db:"index_name" json:"IndexName"`
	ColumnName string `db:"column_name" json:"ColumnName"`
	IsUnique   bool   `db:"is_unique" json:"IsUnique"`
	IndexType  string `db:"index_type" json:"IndexType"`
	IsPrimary  bool   `db:"is_primary" json:"IsPrimary"`
}

IndexInfo represents database indexes

type JSONBlock added in v1.0.8

type JSONBlock struct {
	RawCode    string      `json:"raw_code"`
	ParsedJSON interface{} `json:"parsed_json,omitempty"`
	Language   string      `json:"language"`
	Error      string      `json:"error,omitempty"`
}

JSONBlock represents a JSON code block with parsed data

type RAGConfig

type RAGConfig struct {
	GeminiAPIKey         string
	GeminiModel          string
	GeminiEmbeddingModel string
	PineconeAPIKey       string
	PineconeIndexName    string
	PineconeIndexHost    string
}

type RAGPineconeGemini

type RAGPineconeGemini struct {
	DbClient        *pinecone.Client
	IndexConn       *pinecone.IndexConnection
	GeminiClient    *genai.Client
	IndexHost       string
	EmbeddingModel  *genai.EmbeddingModel
	GenerativeModel *genai.GenerativeModel
}

func (*RAGPineconeGemini) Embed

func (r *RAGPineconeGemini) Embed(text string) ([]float32, error)

implement the RAGmodel interface for the RAGConfig

func (*RAGPineconeGemini) Match

func (r *RAGPineconeGemini) Match(namespace string, query string, topK int) ([]*pinecone.ScoredVector, error)

func (*RAGPineconeGemini) QueryAgent

func (r *RAGPineconeGemini) QueryAgent(namespace string, schema string, query string, topK int) (*AgentResponse, error)

QueryAgent queries the agent with the given namespace, schema, query, and topK this is the main function that will be used to query in agent mode and get the response

func (*RAGPineconeGemini) QueryChat added in v1.0.3

func (r *RAGPineconeGemini) QueryChat(query string) (ChatbotResponse, error)

QueryChat implements a specialized version of query for chat interactions It retrieves data from the vector database using the specified namespace and formats a response using the chatbot prompt template

func (*RAGPineconeGemini) Report

func (r *RAGPineconeGemini) Report(analytics string, schema string) (string, error)

generate a report to a project manager based on the analytics of there database the report should be in a markdown format

type RAGmodel

type RAGmodel interface {
	Embed(text string) ([]float32, error)
	Match(namespace string, query string, topK int) ([]*pinecone.ScoredVector, error)
	QueryAgent(namespace string, schema string, query string, topK int) (*AgentResponse, error)
	Report(analytics string, schema string) (string, error)
	QueryChat(query string) (ChatbotResponse, error)
}

func GetRAG

func GetRAG(config *RAGConfig) RAGmodel

func GetRAGTest

func GetRAGTest() RAGmodel

type SQLBlock added in v1.0.8

type SQLBlock struct {
	Code      string `json:"code"`
	Language  string `json:"language"`
	QueryType string `json:"query_type"`
}

SQLBlock represents a SQL code block with query type

type Schema

type Schema struct {
	Tables map[string]TableInfo `json:"TABLES"`
}

type Table added in v1.0.7

type Table struct {
	TableName   string           `db:"table_name" json:"TableName"`
	Columns     []TableColumn    `db:"columns" json:"Columns"`
	Constraints []ConstraintInfo `db:"constraints" json:"Constraints"`
	Indexes     []IndexInfo      `db:"indexes" json:"Indexes"`
}

type TableColumn added in v1.0.7

type TableColumn struct {
	TableName              string  `db:"table_name" json:"TableName"`
	ColumnName             string  `db:"column_name" json:"ColumnName"`
	DataType               string  `db:"data_type" json:"DataType"`
	IsNullable             bool    `db:"is_nullable" json:"IsNullable"`
	ColumnDefault          *string `db:"column_default" json:"ColumnDefault"`
	CharacterMaximumLength *int    `db:"character_maximum_length" json:"CharacterMaximumLength"`
	NumericPrecision       *int    `db:"numeric_precision" json:"NumericPrecision"`
	NumericScale           *int    `db:"numeric_scale" json:"NumericScale"`
	OrdinalPosition        int     `db:"ordinal_position" json:"OrdinalPosition"`
}

TableColumn represents a database column with its properties

type TableInfo

type TableInfo struct {
	Columns     map[string]ColumnInfo `json:"COLUMNS"`
	PrimaryKeys []string              `json:"PRIMARY_KEYS"`
	ForeignKeys []ForeignKeyInfo      `json:"FOREIGN_KEYS"`
	Checks      []interface{}         `json:"CHECKS"`
	Indexes     [][]string            `json:"INDEXES"`
	Comment     *string               `json:"COMMENT"`
}

Jump to

Keyboard shortcuts

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