Skip to main content

rag

实例名实例描述
QUERY_ENHANCE_TYPE_BASIC(string) "basic"
QUERY_ENHANCE_TYPE_EXACT_KEYWORD_SEARCH(string) "exact_keyword_search"
QUERY_ENHANCE_TYPE_GENERALIZE_QUERY(string) "generalize_query"
QUERY_ENHANCE_TYPE_HYPOTHETICAL_ANSWER(string) "hypothetical_answer"
QUERY_ENHANCE_TYPE_SPLIT_QUERY(string) "split_query"
函数名函数描述/介绍
rag.AddDocument_addDocument 向指定集合添加文档
rag.BuildCollectionFromFile
rag.BuildCollectionFromRaw
rag.BuildCollectionFromReader
rag.BuildIndexKnowledgeFromFile
rag.BuildKnowledgeFromEntityRepos
rag.BuildSearchIndexKnowledgeBuildSearchIndexKnowledge builds a search index for the given text content. It generates 5-10 search questions that users might ask to find this cont...
rag.BuildSearchIndexKnowledgeFromFileBuildSearchIndexKnowledgeFromFile builds a search index from a file. It reads the file content and calls BuildSearchIndexKnowledge. Parameters: ...
rag.DBQueryCountVectorsByEntry_dbQueryCountVectorsByEntryID 根据 entry_id 计算向量文档数量 用于检查某个知识条目有多少向量索引 Parameters: - entryID: 知识条目的 HiddenIndex - opts: 查询选项
rag.DBQueryEntity_dbQueryEntity 数据库直接查询实体 使用 SQL 模糊搜索,不使用语义搜索,速度非常快 适合去重检查、快速验证等场景 Parameters: - keyword: 搜索关键词 - opts: 查询选项(集合、限制、偏移等)
rag.DBQueryKnowledge_dbQueryKnowledge 数据库直接查询知识库条目 使用 SQL 模糊搜索,不使用语义搜索,速度非常快(~2ms) 适合去重检查、快速验证等场景 Parameters: - keyword: 搜索关键词 - opts: 查询选项(集合、限制、偏移等)
rag.DBQueryKnowledgeExists_dbQueryKnowledgeExists 检查知识条目是否存在且有对应的向量索引 这个函数用于增量更新时的去重检查 只有当知识条目存在且有对应的向量文档时,才认为该条目已被完整索引 Parameters: - keyword: 搜索关键词(通常是工具/插件名称) - op...
rag.DBQueryUniqueKnowledgeTitles_dbQueryUniqueKnowledgeTitles 获取唯一的知识标题列表 使用 SQL DISTINCT 查询,返回不重复的 KnowledgeTitle 列表 适合增量更新时的快速去重检查 Parameters: - opts: 查询选项(集合、限制等) Retur...
rag.DBQueryVectorDocument_dbQueryVectorDocument 数据库直接查询向量文档 使用 SQL 模糊搜索,不使用语义搜索,速度非常快 适合去重检查、快速验证等场景 Parameters: - keyword: 搜索关键词 - opts: 查询选项(集合、限制、偏移等)
rag.DeleteAllKnowledgeBase_deleteAllKnowledgeBase 删除所有知识库及其关联的 RAG 内容 清空所有: RAG 向量库、RAG 集合综述库、知识库条目库、知识库集合、问题索引库等
rag.DeleteCollection_deleteCollection 删除指定的 RAG 集合
rag.DeleteDocument_deleteDocument 从指定集合删除文档
rag.DeleteKnowledgeBase_deleteKnowledgeBase 删除指定的知识库及其关联的 RAG 内容 包括: RAG 向量库、RAG 集合综述库、知识库条目库、知识库集合、问题索引库等
rag.DeleteRAG_deleteRAG 删除指定的 RAG 系统
rag.Embedding_embedding 生成文本的嵌入向量 使用默认的嵌入服务生成文本的向量表示(优先使用在线服务,回退到本地服务)
rag.EnableMockMode
rag.Export
rag.Get
rag.GetCollection
rag.GetCollectionInfo_getCollectionInfo 获取指定集合的详细信息
rag.HasCollection_hasCollection 检查指定集合是否存在
rag.Import
rag.ListCollection_listCollection 获取所有 RAG 集合列表
rag.ListRAG_listRAG 列出所有 RAG 系统列表
rag.LocalEmbedding_localEmbedding 使用本地嵌入服务生成文本的向量表示 本地服务需要安装本地模型(如 Qwen3-Embedding-0.6B-Q4_K_M)
rag.NewRagDatabase
rag.NewTempRagDatabase_newTempRagDatabase 创建临时 RAG 数据库
rag.OnlineEmbedding_onlineEmbedding 使用在线嵌入服务生成文本的向量表示 使用 AIBalance 免费在线服务,无需安装本地模型
rag.Query_query 统一的查询/搜索接口 支持多种查询模式: 1. 无参数 - 查询所有集合 2. queryCollection/queryCollections - 指定集合查询 3. queryRAGFilename - 从 RAG 文件导入后查询
rag.QueryDocuments_queryDocuments 在指定集合中查询文档
rag.aiService
rag.aiServiceType
rag.analyzeConcurrency
rag.buildFilter
rag.buildQuery
rag.chunkSize
rag.ctx
rag.db
rag.dbQueryCollection_dbQueryCollection 指定查询的集合名称(单个)
rag.dbQueryCollections_dbQueryCollections 指定查询的多个集合名称
rag.dbQueryCtx_dbQueryCtx 设置查询上下文
rag.dbQueryDB_dbQueryDB 指定数据库连接
rag.dbQueryLimit_dbQueryLimit 设置查询结果数量限制
rag.dbQueryOffset_dbQueryOffset 设置查询偏移量(用于分页)
rag.dbQueryRAGFilename_dbQueryRAGFilename 从 RAG 文件导入后查询 自动导入 RAG 文件到临时集合,然后在该集合上执行查询
rag.disableERM
rag.disableIndex
rag.docMetadataWithDocumentMetadataKeyValue sets document metadata key-value pairs
rag.docRawMetadataWithDocumentRawMetadata sets raw document metadata
rag.documentHandler
rag.embeddingHandle_embeddingHandle 创建自定义嵌入处理器
rag.enableQuestionIndex
rag.entryLength
rag.extraPrompt
rag.getEntityFilter
rag.importNameWithRAGCollectionName sets the specific collection name to query
rag.importOverwrite
rag.importRebuildGraph
rag.khopLimit
rag.khopkWithKHopK 设置k-hop的跳数,k>=2时返回k-hop路径,k=0返回所有路径
rag.khopkMaxWithKHopKMax 设置最大路径长度,最小值为2
rag.khopkMinWithKHopKMin 设置最小路径长度,最小值为2
rag.lazyEmbedding
rag.log
rag.noEntityRepository_noEntityRepository 禁用实体仓库
rag.noHNSWGraph
rag.noKnowledgeBase_noKnowledgeBase 禁用知识库
rag.noMetadata
rag.noOriginInput
rag.noPotentialQuestionsNoPotentialQuestions returns a RAGSystemConfigOption that excludes potential_questions from metadata This is a convenient shortcut for WithNoPotential...
rag.onlyPQCode
rag.pathDepth
rag.progressHandler
rag.queryCollectionWithRAGCollectionName sets the specific collection name to query
rag.queryCollections_queryCollections 指定查询的多个集合名称
rag.queryConcurrentWithRAGConcurrent sets the concurrency level for query operations
rag.queryCtxWithRAGCtx sets the context for RAG query operations
rag.queryEnhanceWithRAGEnhance sets the enhancement strategies to apply
rag.queryLimitWithRAGLimit sets the maximum number of results to return
rag.queryRAGFilename_queryRAGFilename 从 RAG 文件导入后查询(自动导入) 适合法规条文、技术规范等精确搜索场景
rag.queryScoreLimitWithRAGCollectionScoreLimit sets the score limit for collection filtering
rag.querySimilarityThresholdWithRAGSimilarityThreshold sets the minimum similarity threshold for results
rag.queryStatusWithRAGQueryStatus sets the query status callback function
rag.queryTypeWithRAGDocumentType sets the document type filter
rag.ragCosineDistance
rag.ragDescription
rag.ragEmbeddingModel
rag.ragForceNewWithForceNew sets whether to force creation of new collection
rag.ragHNSWParametersWithHNSWParameters sets HNSW parameters
rag.ragImportFile
rag.ragModelDimensionWithModelDimension sets the model dimension
rag.serialVersionUID
rag.setSearchMeta_setSearchMeta 快捷设置搜索元数据 (search_type 和 search_target) 用于同时设置 search_type 和 search_target 两个元数据字段 Parameters: - searchType: 搜索类型,例如 "AI工具&#...
rag.statusCard

函数定义#

AddDocument#

详细描述#

_addDocument 向指定集合添加文档

Example:


    err = rag.AddDocument("my_collection", "doc1", "content", {"key": "value"})

定义#

AddDocument(knowledgeBaseName string, documentName string, document string, metadata map[string]any, opts ...rag.RAGSystemConfigOption) error

参数#

参数名参数类型参数解释
knowledgeBaseNamestring
documentNamestring
documentstring
metadatamap[string]any
opts...rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1error

BuildCollectionFromFile#

详细描述#

定义#

BuildCollectionFromFile(kbName string, path string, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)

参数#

参数名参数类型参数解释
kbNamestring
pathstring
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1<-chan *schema.KnowledgeBaseEntry
r2error

BuildCollectionFromRaw#

详细描述#

定义#

BuildCollectionFromRaw(kbName string, content []byte, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)

参数#

参数名参数类型参数解释
kbNamestring
content[]byte
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1<-chan *schema.KnowledgeBaseEntry
r2error

BuildCollectionFromReader#

详细描述#

定义#

BuildCollectionFromReader(kbName string, reader io.Reader, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)

参数#

参数名参数类型参数解释
kbNamestring
readerio.Reader
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1<-chan *schema.KnowledgeBaseEntry
r2error

BuildIndexKnowledgeFromFile#

详细描述#

定义#

BuildIndexKnowledgeFromFile(kbName string, path string, option ...any) error

参数#

参数名参数类型参数解释
kbNamestring
pathstring
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1error

BuildKnowledgeFromEntityRepos#

详细描述#

定义#

BuildKnowledgeFromEntityRepos(name string, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)

参数#

参数名参数类型参数解释
namestring
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1<-chan *schema.KnowledgeBaseEntry
r2error

BuildSearchIndexKnowledge#

详细描述#

BuildSearchIndexKnowledge builds a search index for the given text content.

It generates 5-10 search questions that users might ask to find this content,

and stores the original content as the knowledge entry.

Parameters:

  • kbName: the knowledge base name

  • text: the content to index (e.g., tool description, usage, parameters)

  • options: optional configuration (rag options, AI options, etc.)

The function will:

  1. Use AI to generate 5-10 search questions based on the text

  2. Store the original text as the knowledge entry

  3. Set docMetadata with question_index and search_target for each question

Example:

text = `工具名:端口扫描器目标:扫描目标主机的开放端口用法:指定目标IP和端口范围,工具会返回开放的端口列表`result = rag.BuildSearchIndexKnowledge("my-tools", text)~println("Generated questions:", result.Questions)

定义#

BuildSearchIndexKnowledge(kbName string, text string, option ...any) (*aiforge.SearchIndexResult, error)

参数#

参数名参数类型参数解释
kbNamestring
textstring
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1*aiforge.SearchIndexResult
r2error

BuildSearchIndexKnowledgeFromFile#

详细描述#

BuildSearchIndexKnowledgeFromFile builds a search index from a file.

It reads the file content and calls BuildSearchIndexKnowledge.

Parameters:

  • kbName: the knowledge base name

  • filename: the path to the file containing the content to index

  • options: optional configuration (rag options, AI options, etc.)

Example:

result = rag.BuildSearchIndexKnowledgeFromFile("my-tools", "/path/to/tool-description.txt")~println("Generated questions:", result.Questions)

定义#

BuildSearchIndexKnowledgeFromFile(kbName string, filename string, option ...any) (*aiforge.SearchIndexResult, error)

参数#

参数名参数类型参数解释
kbNamestring
filenamestring
option...any

返回值#

返回值(顺序)返回值类型返回值解释
r1*aiforge.SearchIndexResult
r2error

DBQueryCountVectorsByEntry#

详细描述#

_dbQueryCountVectorsByEntryID 根据 entry_id 计算向量文档数量

用于检查某个知识条目有多少向量索引

Parameters:

  • entryID: 知识条目的 HiddenIndex

  • opts: 查询选项

Example:


    count = rag.DBQueryCountVectorsByEntryID("abc123", rag.dbQueryRAGFilename("/tmp/caps.rag"))~    println("This entry has", count, "vector indexes")

定义#

DBQueryCountVectorsByEntry(entryID string, opts ...DBQueryOption) (int, error)

参数#

参数名参数类型参数解释
entryIDstring
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1int
r2error

DBQueryEntity#

详细描述#

_dbQueryEntity 数据库直接查询实体

使用 SQL 模糊搜索,不使用语义搜索,速度非常快

适合去重检查、快速验证等场景

Parameters:

  • keyword: 搜索关键词

  • opts: 查询选项(集合、限制、偏移等)

Example:


    // 基本用法    entities = rag.DBQueryEntity("用户")~    for _, entity := range entities {        println(entity.EntityName, entity.EntityType)    }
    // 指定集合    entities = rag.DBQueryEntity("关键词", rag.dbQueryCollection("my-repo"))~
    // 从 RAG 文件查询    entities = rag.DBQueryEntity("关键词", rag.dbQueryRAGFilename("/tmp/my.rag"))~

定义#

DBQueryEntity(keyword string, opts ...DBQueryOption) ([]*schema.ERModelEntity, error)

参数#

参数名参数类型参数解释
keywordstring
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1[]*schema.ERModelEntity
r2error

DBQueryKnowledge#

详细描述#

_dbQueryKnowledge 数据库直接查询知识库条目

使用 SQL 模糊搜索,不使用语义搜索,速度非常快(~2ms)

适合去重检查、快速验证等场景

Parameters:

  • keyword: 搜索关键词

  • opts: 查询选项(集合、限制、偏移等)

Example:


    // 基本用法    entries = rag.DBQueryKnowledge("get_location")~    for _, entry := range entries {        println(entry.KnowledgeTitle)    }
    // 指定集合    entries = rag.DBQueryKnowledge("关键词", rag.dbQueryCollection("my-collection"))~
    // 从 RAG 文件查询    entries = rag.DBQueryKnowledge("关键词", rag.dbQueryRAGFilename("/tmp/my.rag"))~
    // 分页查询    entries = rag.DBQueryKnowledge("关键词", rag.dbQueryLimit(10), rag.dbQueryOffset(20))~

定义#

DBQueryKnowledge(keyword string, opts ...DBQueryOption) ([]*schema.KnowledgeBaseEntry, error)

参数#

参数名参数类型参数解释
keywordstring
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1[]*schema.KnowledgeBaseEntry
r2error

DBQueryKnowledgeExists#

详细描述#

_dbQueryKnowledgeExists 检查知识条目是否存在且有对应的向量索引

这个函数用于增量更新时的去重检查

只有当知识条目存在且有对应的向量文档时,才认为该条目已被完整索引

Parameters:

  • keyword: 搜索关键词(通常是工具/插件名称)

  • opts: 查询选项

Returns:

  • *DBQueryKnowledgeExistsResult: 检查结果,包含是否存在、知识条目、向量数量等

Example:


    result = rag.DBQueryKnowledgeExists("get_location", rag.dbQueryRAGFilename("/tmp/caps.rag"))~    if result.Exists {        println("Already indexed with", result.VectorDocCount, "vectors")    }

定义#

DBQueryKnowledgeExists(keyword string, opts ...DBQueryOption) (*DBQueryKnowledgeExistsResult, error)

参数#

参数名参数类型参数解释
keywordstring
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1*DBQueryKnowledgeExistsResult
r2error

DBQueryUniqueKnowledgeTitles#

详细描述#

_dbQueryUniqueKnowledgeTitles 获取唯一的知识标题列表

使用 SQL DISTINCT 查询,返回不重复的 KnowledgeTitle 列表

适合增量更新时的快速去重检查

Parameters:

  • opts: 查询选项(集合、限制等)

Returns:

  • []string: 唯一的知识标题列表

Example:


    // 获取所有唯一的知识标题    titles = rag.DBQueryUniqueKnowledgeTitles(rag.dbQueryCollection("my-collection"))~    for _, title := range titles {        println(title)    }
    // 从 RAG 文件查询    titles = rag.DBQueryUniqueKnowledgeTitles(rag.dbQueryRAGFilename("/tmp/my.rag"))~

定义#

DBQueryUniqueKnowledgeTitles(opts ...DBQueryOption) ([]string, error)

参数#

参数名参数类型参数解释
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1[]string
r2error

DBQueryVectorDocument#

详细描述#

_dbQueryVectorDocument 数据库直接查询向量文档

使用 SQL 模糊搜索,不使用语义搜索,速度非常快

适合去重检查、快速验证等场景

Parameters:

  • keyword: 搜索关键词

  • opts: 查询选项(集合、限制、偏移等)

Example:


    // 基本用法    docs = rag.DBQueryVectorDocument("关键词")~    for _, doc := range docs {        println(doc.DocumentID, doc.Content[:100])    }
    // 指定集合    docs = rag.DBQueryVectorDocument("关键词", rag.dbQueryCollection("my-collection"))~
    // 从 RAG 文件查询    docs = rag.DBQueryVectorDocument("关键词", rag.dbQueryRAGFilename("/tmp/my.rag"))~

定义#

DBQueryVectorDocument(keyword string, opts ...DBQueryOption) ([]*schema.VectorStoreDocument, error)

参数#

参数名参数类型参数解释
keywordstring
opts...DBQueryOption

返回值#

返回值(顺序)返回值类型返回值解释
r1[]*schema.VectorStoreDocument
r2error

DeleteAllKnowledgeBase#

详细描述#

_deleteAllKnowledgeBase 删除所有知识库及其关联的 RAG 内容

清空所有: RAG 向量库、RAG 集合综述库、知识库条目库、知识库集合、问题索引库等

Example:


    err = rag.DeleteAllKnowledgeBase()

定义#

DeleteAllKnowledgeBase() error

返回值#

返回值(顺序)返回值类型返回值解释
r1error

DeleteCollection#

详细描述#

_deleteCollection 删除指定的 RAG 集合

Example:


    err = rag.DeleteCollection("my_collection")

定义#

DeleteCollection(name string) error

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1error

DeleteDocument#

详细描述#

_deleteDocument 从指定集合删除文档

Example:


    err = rag.DeleteDocument("my_collection", "doc1")

定义#

DeleteDocument(knowledgeBaseName string, documentName string, opts ...rag.RAGSystemConfigOption) error

参数#

参数名参数类型参数解释
knowledgeBaseNamestring
documentNamestring
opts...rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1error

DeleteKnowledgeBase#

详细描述#

_deleteKnowledgeBase 删除指定的知识库及其关联的 RAG 内容

包括: RAG 向量库、RAG 集合综述库、知识库条目库、知识库集合、问题索引库等

Example:


    err = rag.DeleteKnowledgeBase("my_knowledge_base")

定义#

DeleteKnowledgeBase(name string) error

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1error

DeleteRAG#

详细描述#

_deleteRAG 删除指定的 RAG 系统

Example:


    err = rag.DeleteRAG("my_rag")

定义#

DeleteRAG(name string) error

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1error

Embedding#

详细描述#

_embedding 生成文本的嵌入向量

使用默认的嵌入服务生成文本的向量表示(优先使用在线服务,回退到本地服务)

Example:


    result, err = rag.Embedding("你好")    if err != nil {        // handle error    }    // result is []float32

定义#

Embedding(text string) ([]float32, error)

参数#

参数名参数类型参数解释
textstring

返回值#

返回值(顺序)返回值类型返回值解释
r1[]float32
r2error

EnableMockMode#

详细描述#

定义#

EnableMockMode()

Export#

详细描述#

定义#

Export(collectionName string, fileName string, opts ...RAGSystemConfigOption) error

参数#

参数名参数类型参数解释
collectionNamestring
fileNamestring
opts...RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1error

Get#

详细描述#

定义#

Get(name string, opts ...RAGSystemConfigOption) (*RAGSystem, error)

参数#

参数名参数类型参数解释
namestring
opts...RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1*RAGSystem
r2error

GetCollection#

详细描述#

定义#

GetCollection(name string, opts ...RAGSystemConfigOption) (*RAGSystem, error)

参数#

参数名参数类型参数解释
namestring
opts...RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1*RAGSystem
r2error

GetCollectionInfo#

详细描述#

_getCollectionInfo 获取指定集合的详细信息

Example:


    info, err = rag.GetCollectionInfo("my_collection")

定义#

GetCollectionInfo(name string) (*vectorstore.CollectionInfo, error)

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1*vectorstore.CollectionInfo
r2error

HasCollection#

详细描述#

_hasCollection 检查指定集合是否存在

Example:


    exists = rag.HasCollection("my_collection")

定义#

HasCollection(name string) bool

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1bool

Import#

详细描述#

定义#

Import(inputPath string, optFuncs ...RAGSystemConfigOption) error

参数#

参数名参数类型参数解释
inputPathstring
optFuncs...RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1error

ListCollection#

详细描述#

_listCollection 获取所有 RAG 集合列表

Example:


    collections = rag.ListCollection()

定义#

ListCollection() []string

返回值#

返回值(顺序)返回值类型返回值解释
r1[]string

ListRAG#

详细描述#

_listRAG 列出所有 RAG 系统列表

Example:


    ragSystems = rag.ListRAG()

定义#

ListRAG() []string

返回值#

返回值(顺序)返回值类型返回值解释
r1[]string

LocalEmbedding#

详细描述#

_localEmbedding 使用本地嵌入服务生成文本的向量表示

本地服务需要安装本地模型(如 Qwen3-Embedding-0.6B-Q4_K_M)

Example:


    result, err = rag.LocalEmbedding("你好")    if err != nil {        // handle error - 本地服务不可用    }    // result is []float32, dimension: 1024

定义#

LocalEmbedding(text string) ([]float32, error)

参数#

参数名参数类型参数解释
textstring

返回值#

返回值(顺序)返回值类型返回值解释
r1[]float32
r2error

NewRagDatabase#

详细描述#

定义#

NewRagDatabase(path string) (*gorm.DB, error)

参数#

参数名参数类型参数解释
pathstring

返回值#

返回值(顺序)返回值类型返回值解释
r1*gorm.DB
r2error

NewTempRagDatabase#

详细描述#

_newTempRagDatabase 创建临时 RAG 数据库

Example:


    db, err = rag.NewTempRagDatabase()

定义#

NewTempRagDatabase() (*gorm.DB, error)

返回值#

返回值(顺序)返回值类型返回值解释
r1*gorm.DB
r2error

OnlineEmbedding#

详细描述#

_onlineEmbedding 使用在线嵌入服务生成文本的向量表示

使用 AIBalance 免费在线服务,无需安装本地模型

Example:


    result, err = rag.OnlineEmbedding("你好")    if err != nil {        // handle error - 在线服务不可用    }    // result is []float32, dimension: 1024

定义#

OnlineEmbedding(text string) ([]float32, error)

参数#

参数名参数类型参数解释
textstring

返回值#

返回值(顺序)返回值类型返回值解释
r1[]float32
r2error

Query#

详细描述#

_query 统一的查询/搜索接口

支持多种查询模式:

  1. 无参数 - 查询所有集合

  2. queryCollection/queryCollections - 指定集合查询

  3. queryRAGFilename - 从 RAG 文件导入后查询

Example:


    // 查询所有集合    results = rag.Query("如何使用 XSS 检测?")~
    // 查询指定集合(单个)    results = rag.Query("如何使用 MITM 插件?", rag.queryCollection("yaklang-yakscript-plugins"))~
    // 查询多个集合    results = rag.Query("XSS 漏洞", rag.queryCollections("plugins", "tools", "docs"))~
    // 从 RAG 文件导入后查询(适合法规条文等精确搜索)    results = rag.Query("法规第2.3条", rag.queryRAGFilename("/path/to/law.rag"))~
    // 组合使用    results = rag.Query("XSS 漏洞",        rag.queryCollections("plugins"),        rag.queryLimit(20),        rag.querySimilarityThreshold(0.5),        rag.queryEnhance(            rag.QUERY_ENHANCE_TYPE_HYPOTHETICAL_ANSWER,            rag.QUERY_ENHANCE_TYPE_EXACT_KEYWORD_SEARCH,        ),    )~

定义#

Query(query string, opts ...rag.RAGSystemConfigOption) (<-chan *rag.RAGSearchResult, error)

参数#

参数名参数类型参数解释
querystring
opts...rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1<-chan *rag.RAGSearchResult
r2error

QueryDocuments#

详细描述#

_queryDocuments 在指定集合中查询文档

Example:


    results, err = rag.QueryDocuments("my_collection", "query", 10)

定义#

QueryDocuments(knowledgeBaseName string, query string, limit int, opts ...rag.RAGSystemConfigOption) ([]*rag.SearchResult, error)

参数#

参数名参数类型参数解释
knowledgeBaseNamestring
querystring
limitint
opts...rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1[]*rag.SearchResult
r2error

aiService#

详细描述#

定义#

aiService(aiService aicommon.AICallbackType) RAGSystemConfigOption

参数#

参数名参数类型参数解释
aiServiceaicommon.AICallbackType

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

aiServiceType#

详细描述#

定义#

aiServiceType(aiServiceName string, aiServiceConfig ...aispec.AIConfigOption) RAGSystemConfigOption

参数#

参数名参数类型参数解释
aiServiceNamestring
aiServiceConfig...aispec.AIConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

analyzeConcurrency#

详细描述#

定义#

analyzeConcurrency(concurrency int) AnalysisOption

参数#

参数名参数类型参数解释
concurrencyint

返回值#

返回值(顺序)返回值类型返回值解释
r1AnalysisOption

buildFilter#

详细描述#

定义#

buildFilter(filter *ypb.EntityFilter) RAGSystemConfigOption

参数#

参数名参数类型参数解释
filter*ypb.EntityFilter

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

buildQuery#

详细描述#

定义#

buildQuery(query string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
querystring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

chunkSize#

详细描述#

定义#

chunkSize(size int64) Option

参数#

参数名参数类型参数解释
sizeint64

返回值#

返回值(顺序)返回值类型返回值解释
r1Option

ctx#

详细描述#

定义#

ctx(ctx context.Context) AnalysisOption

参数#

参数名参数类型参数解释
ctxcontext.Context

返回值#

返回值(顺序)返回值类型返回值解释
r1AnalysisOption

db#

详细描述#

定义#

db(db *gorm.DB) RAGSystemConfigOption

参数#

参数名参数类型参数解释
db*gorm.DB

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

dbQueryCollection#

详细描述#

_dbQueryCollection 指定查询的集合名称(单个)

Example:


    results = rag.DBQueryKnowledge("关键词", rag.dbQueryCollection("my-collection"))

定义#

dbQueryCollection(name string) DBQueryOption

参数#

参数名参数类型参数解释
namestring

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryCollections#

详细描述#

_dbQueryCollections 指定查询的多个集合名称

Example:


    results = rag.DBQueryKnowledge("关键词", rag.dbQueryCollections("col1", "col2"))

定义#

dbQueryCollections(names ...string) DBQueryOption

参数#

参数名参数类型参数解释
names...string

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryCtx#

详细描述#

_dbQueryCtx 设置查询上下文

Example:


    ctx = context.WithTimeout(context.Background(), 10*time.Second)    results = rag.DBQueryKnowledge("关键词", rag.dbQueryCtx(ctx))

定义#

dbQueryCtx(ctx context.Context) DBQueryOption

参数#

参数名参数类型参数解释
ctxcontext.Context

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryDB#

详细描述#

_dbQueryDB 指定数据库连接

Example:


    db = rag.NewRagDatabase("/path/to/db")    results = rag.DBQueryKnowledge("关键词", rag.dbQueryDB(db))

定义#

dbQueryDB(db *gorm.DB) DBQueryOption

参数#

参数名参数类型参数解释
db*gorm.DB

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryLimit#

详细描述#

_dbQueryLimit 设置查询结果数量限制

Example:


    results = rag.DBQueryKnowledge("关键词", rag.dbQueryLimit(10))

定义#

dbQueryLimit(limit int) DBQueryOption

参数#

参数名参数类型参数解释
limitint

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryOffset#

详细描述#

_dbQueryOffset 设置查询偏移量(用于分页)

Example:


    results = rag.DBQueryKnowledge("关键词", rag.dbQueryOffset(20), rag.dbQueryLimit(10))

定义#

dbQueryOffset(offset int) DBQueryOption

参数#

参数名参数类型参数解释
offsetint

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

dbQueryRAGFilename#

详细描述#

_dbQueryRAGFilename 从 RAG 文件导入后查询

自动导入 RAG 文件到临时集合,然后在该集合上执行查询

Example:


    results = rag.DBQueryKnowledge("关键词", rag.dbQueryRAGFilename("/path/to/my.rag"))

定义#

dbQueryRAGFilename(filename string) DBQueryOption

参数#

参数名参数类型参数解释
filenamestring

返回值#

返回值(顺序)返回值类型返回值解释
r1DBQueryOption

disableERM#

详细描述#

定义#

disableERM(disable bool) RefineOption

参数#

参数名参数类型参数解释
disablebool

返回值#

返回值(顺序)返回值类型返回值解释
r1RefineOption

disableIndex#

详细描述#

定义#

disableIndex(disable bool) RefineOption

参数#

参数名参数类型参数解释
disablebool

返回值#

返回值(顺序)返回值类型返回值解释
r1RefineOption

docMetadata#

详细描述#

WithDocumentMetadataKeyValue sets document metadata key-value pairs

定义#

docMetadata(key string, value any) RAGSystemConfigOption

参数#

参数名参数类型参数解释
keystring
valueany

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

docRawMetadata#

详细描述#

WithDocumentRawMetadata sets raw document metadata

定义#

docRawMetadata(metadata map[string]any) RAGSystemConfigOption

参数#

参数名参数类型参数解释
metadatamap[string]any

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

documentHandler#

详细描述#

定义#

documentHandler(documentHandler func(doc schema.VectorStoreDocument) (schema.VectorStoreDocument, error)) RAGSystemConfigOption

参数#

参数名参数类型参数解释
documentHandlerfunc(doc schema.VectorStoreDocument) (schema.VectorStoreDocument, error)

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

embeddingHandle#

详细描述#

_embeddingHandle 创建自定义嵌入处理器

Example:


    embeddingOpt = rag.embeddingHandle((text) => {        return [0.1, 0.2, 0.3] // 返回嵌入向量    })

定义#

embeddingHandle(handle func(text string) any) rag.RAGSystemConfigOption

参数#

参数名参数类型参数解释
handlefunc(text string) any

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

enableQuestionIndex#

详细描述#

定义#

enableQuestionIndex(enable bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
enablebool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

entryLength#

详细描述#

定义#

entryLength(length int) RefineOption

参数#

参数名参数类型参数解释
lengthint

返回值#

返回值(顺序)返回值类型返回值解释
r1RefineOption

extraPrompt#

详细描述#

定义#

extraPrompt(prompt string) AnalysisOption

参数#

参数名参数类型参数解释
promptstring

返回值#

返回值(顺序)返回值类型返回值解释
r1AnalysisOption

getEntityFilter#

详细描述#

定义#

getEntityFilter(reposName string, entityTypes []string, names []string, HiddenIndex []string, keywords []string) *ypb.EntityFilter

参数#

参数名参数类型参数解释
reposNamestring
entityTypes[]string
names[]string
HiddenIndex[]string
keywords[]string

返回值#

返回值(顺序)返回值类型返回值解释
r1*ypb.EntityFilter

importName#

详细描述#

WithRAGCollectionName sets the specific collection name to query

定义#

importName(collectionName string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
collectionNamestring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

importOverwrite#

详细描述#

定义#

importOverwrite(overwriteExisting bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
overwriteExistingbool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

importRebuildGraph#

详细描述#

定义#

importRebuildGraph(rebuildHNSWIndex bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
rebuildHNSWIndexbool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

khopLimit#

详细描述#

定义#

khopLimit(k int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
kint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

khopk#

详细描述#

WithKHopK 设置k-hop的跳数,k>=2时返回k-hop路径,k=0返回所有路径

定义#

khopk(k int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
kint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

khopkMax#

详细描述#

WithKHopKMax 设置最大路径长度,最小值为2

定义#

khopkMax(kMax int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
kMaxint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

khopkMin#

详细描述#

WithKHopKMin 设置最小路径长度,最小值为2

定义#

khopkMin(kMin int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
kMinint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

lazyEmbedding#

详细描述#

定义#

lazyEmbedding(lazy ...bool) rag.RAGSystemConfigOption

参数#

参数名参数类型参数解释
lazy...bool

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

log#

详细描述#

定义#

log(handler func(format string, args ...any)) AnalysisOption

参数#

参数名参数类型参数解释
handlerfunc(format string, args ...any)

返回值#

返回值(顺序)返回值类型返回值解释
r1AnalysisOption

noEntityRepository#

详细描述#

_noEntityRepository 禁用实体仓库

Example:


    rag.noEntityRepository()

定义#

noEntityRepository() rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

noHNSWGraph#

详细描述#

定义#

noHNSWGraph(noHNSWGraph bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
noHNSWGraphbool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

noKnowledgeBase#

详细描述#

_noKnowledgeBase 禁用知识库

Example:


    rag.noKnowledgeBase()

定义#

noKnowledgeBase() rag.RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

noMetadata#

详细描述#

定义#

noMetadata(noMetadata bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
noMetadatabool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

noOriginInput#

详细描述#

定义#

noOriginInput(noOriginInput bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
noOriginInputbool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

noPotentialQuestions#

详细描述#

NoPotentialQuestions returns a RAGSystemConfigOption that excludes potential_questions from metadata This is a convenient shortcut for WithNoPotentialQuestions(true)

定义#

noPotentialQuestions() RAGSystemConfigOption

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

onlyPQCode#

详细描述#

定义#

onlyPQCode(onlyPQCode bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
onlyPQCodebool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

pathDepth#

详细描述#

定义#

pathDepth(deep int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
deepint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

progressHandler#

详细描述#

定义#

progressHandler(progressHandler func(percent float64, message string, messageType string)) RAGSystemConfigOption

参数#

参数名参数类型参数解释
progressHandlerfunc(percent float64, message string, messageType string)

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryCollection#

详细描述#

WithRAGCollectionName sets the specific collection name to query

定义#

queryCollection(collectionName string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
collectionNamestring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryCollections#

详细描述#

_queryCollections 指定查询的多个集合名称

Example:


    results = rag.Query("如何使用 MITM 插件?", rag.queryCollections("collection1", "collection2", "collection3"))~

定义#

queryCollections(names ...string) rag.RAGSystemConfigOption

参数#

参数名参数类型参数解释
names...string

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

queryConcurrent#

详细描述#

WithRAGConcurrent sets the concurrency level for query operations

定义#

queryConcurrent(concurrent int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
concurrentint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryCtx#

详细描述#

WithRAGCtx sets the context for RAG query operations

定义#

queryCtx(ctx context.Context) RAGSystemConfigOption

参数#

参数名参数类型参数解释
ctxcontext.Context

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryEnhance#

详细描述#

WithRAGEnhance sets the enhancement strategies to apply

定义#

queryEnhance(enhance ...string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
enhance...string

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryLimit#

详细描述#

WithRAGLimit sets the maximum number of results to return

定义#

queryLimit(limit int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
limitint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryRAGFilename#

详细描述#

_queryRAGFilename 从 RAG 文件导入后查询(自动导入)

适合法规条文、技术规范等精确搜索场景

Example:


    results = rag.Query("法规第2.3条", rag.queryRAGFilename("/path/to/law.rag"))~

定义#

queryRAGFilename(filename string) rag.RAGSystemConfigOption

参数#

参数名参数类型参数解释
filenamestring

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

queryScoreLimit#

详细描述#

WithRAGCollectionScoreLimit sets the score limit for collection filtering

定义#

queryScoreLimit(scoreLimit float64) RAGSystemConfigOption

参数#

参数名参数类型参数解释
scoreLimitfloat64

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

querySimilarityThreshold#

详细描述#

WithRAGSimilarityThreshold sets the minimum similarity threshold for results

定义#

querySimilarityThreshold(threshold float64) RAGSystemConfigOption

参数#

参数名参数类型参数解释
thresholdfloat64

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryStatus#

详细描述#

WithRAGQueryStatus sets the query status callback function

定义#

queryStatus(callback func(label string, i any, tags ...string)) RAGSystemConfigOption

参数#

参数名参数类型参数解释
callbackfunc(label string, i any, tags ...string)

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

queryType#

详细描述#

WithRAGDocumentType sets the document type filter

定义#

queryType(documentType ...string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
documentType...string

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragCosineDistance#

详细描述#

定义#

ragCosineDistance()

ragDescription#

详细描述#

定义#

ragDescription(description string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
descriptionstring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragEmbeddingModel#

详细描述#

定义#

ragEmbeddingModel(model string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
modelstring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragForceNew#

详细描述#

WithForceNew sets whether to force creation of new collection

定义#

ragForceNew(force bool) RAGSystemConfigOption

参数#

参数名参数类型参数解释
forcebool

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragHNSWParameters#

详细描述#

WithHNSWParameters sets HNSW parameters

定义#

ragHNSWParameters(m int, ml float64, efSearch int, efConstruct int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
mint
mlfloat64
efSearchint
efConstructint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragImportFile#

详细描述#

定义#

ragImportFile(importFile string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
importFilestring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

ragModelDimension#

详细描述#

WithModelDimension sets the model dimension

定义#

ragModelDimension(dimension int) RAGSystemConfigOption

参数#

参数名参数类型参数解释
dimensionint

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

serialVersionUID#

详细描述#

定义#

serialVersionUID(serialVersionUID string) RAGSystemConfigOption

参数#

参数名参数类型参数解释
serialVersionUIDstring

返回值#

返回值(顺序)返回值类型返回值解释
r1RAGSystemConfigOption

setSearchMeta#

详细描述#

_setSearchMeta 快捷设置搜索元数据 (search_type 和 search_target)

用于同时设置 search_type 和 search_target 两个元数据字段

Parameters:

  • searchType: 搜索类型,例如 "AI工具", "Yak插件", "aiforge/模版/技能" 等

  • searchTarget: 搜索目标,例如插件名称、工具名称等

Example:

rag.BuildSearchIndexKnowledge("my-tools", text, rag.setSearchMeta("AI工具", "端口扫描器"))

定义#

setSearchMeta(searchType string, searchTarget string) rag.RAGSystemConfigOption

参数#

参数名参数类型参数解释
searchTypestring
searchTargetstring

返回值#

返回值(顺序)返回值类型返回值解释
r1rag.RAGSystemConfigOption

statusCard#

详细描述#

定义#

statusCard(handler func(id string, data any, tags ...string)) AnalysisOption

参数#

参数名参数类型参数解释
handlerfunc(id string, data any, tags ...string)

返回值#

返回值(顺序)返回值类型返回值解释
r1AnalysisOption