函数定义#
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
| 参数名 | 参数类型 | 参数解释 |
|---|
| knowledgeBaseName | string | |
| documentName | string | |
| document | string | |
| metadata | map[string]any | |
| opts | ...rag.RAGSystemConfigOption | |
返回值#
BuildCollectionFromFile#
详细描述#
BuildCollectionFromFile(kbName string, path string, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| kbName | string | |
| path | string | |
| option | ...any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | <-chan *schema.KnowledgeBaseEntry | |
| r2 | error | |
BuildCollectionFromRaw#
详细描述#
BuildCollectionFromRaw(kbName string, content []byte, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| kbName | string | |
| content | []byte | |
| option | ...any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | <-chan *schema.KnowledgeBaseEntry | |
| r2 | error | |
BuildCollectionFromReader#
详细描述#
BuildCollectionFromReader(kbName string, reader io.Reader, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| kbName | string | |
| reader | io.Reader | |
| option | ...any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | <-chan *schema.KnowledgeBaseEntry | |
| r2 | error | |
BuildIndexKnowledgeFromFile#
详细描述#
BuildIndexKnowledgeFromFile(kbName string, path string, option ...any) error
| 参数名 | 参数类型 | 参数解释 |
|---|
| kbName | string | |
| path | string | |
| option | ...any | |
返回值#
BuildKnowledgeFromEntityRepos#
详细描述#
BuildKnowledgeFromEntityRepos(name string, option ...any) (<-chan *schema.KnowledgeBaseEntry, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| name | string | |
| option | ...any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | <-chan *schema.KnowledgeBaseEntry | |
| r2 | error | |
DeleteCollection#
详细描述#
_deleteCollection 删除指定的 RAG 集合
Example:
err = rag.DeleteCollection("my_collection")
DeleteCollection(name string) error
返回值#
DeleteDocument#
详细描述#
_deleteDocument 从指定集合删除文档
Example:
err = rag.DeleteDocument("my_collection", "doc1")
DeleteDocument(knowledgeBaseName string, documentName string, opts ...rag.RAGSystemConfigOption) error
| 参数名 | 参数类型 | 参数解释 |
|---|
| knowledgeBaseName | string | |
| documentName | string | |
| opts | ...rag.RAGSystemConfigOption | |
返回值#
DeleteRAG#
详细描述#
_deleteRAG 删除指定的 RAG 系统
Example:
err = rag.DeleteRAG("my_rag")
DeleteRAG(name string) error
返回值#
EnableMockMode#
详细描述#
EnableMockMode()
Export#
详细描述#
Export(collectionName string, fileName string, opts ...RAGSystemConfigOption) error
| 参数名 | 参数类型 | 参数解释 |
|---|
| collectionName | string | |
| fileName | string | |
| opts | ...RAGSystemConfigOption | |
返回值#
Get#
详细描述#
Get(name string, opts ...RAGSystemConfigOption) (*RAGSystem, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| name | string | |
| opts | ...RAGSystemConfigOption | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *RAGSystem | |
| r2 | error | |
GetCollection#
详细描述#
GetCollection(name string, opts ...RAGSystemConfigOption) (*RAGSystem, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| name | string | |
| opts | ...RAGSystemConfigOption | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *RAGSystem | |
| r2 | error | |
GetCollectionInfo#
详细描述#
_getCollectionInfo 获取指定集合的详细信息
Example:
info, err = rag.GetCollectionInfo("my_collection")
GetCollectionInfo(name string) (*vectorstore.CollectionInfo, error)
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *vectorstore.CollectionInfo | |
| r2 | error | |
HasCollection#
详细描述#
_hasCollection 检查指定集合是否存在
Example:
exists = rag.HasCollection("my_collection")
HasCollection(name string) bool
返回值#
Import#
详细描述#
Import(inputPath string, optFuncs ...RAGSystemConfigOption) error
| 参数名 | 参数类型 | 参数解释 |
|---|
| inputPath | string | |
| optFuncs | ...RAGSystemConfigOption | |
返回值#
ListCollection#
详细描述#
_listCollection 获取所有 RAG 集合列表
Example:
collections = rag.ListCollection()
ListCollection() []string
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | []string | |
ListRAG#
详细描述#
_listRAG 列出所有 RAG 系统列表
Example:
ragSystems = rag.ListRAG()
ListRAG() []string
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | []string | |
NewRagDatabase#
详细描述#
NewRagDatabase(path string) (*gorm.DB, error)
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *gorm.DB | |
| r2 | error | |
NewTempRagDatabase#
详细描述#
_newTempRagDatabase 创建临时 RAG 数据库
Example:
db, err = rag.NewTempRagDatabase()
NewTempRagDatabase() (*gorm.DB, error)
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *gorm.DB | |
| r2 | error | |
Query#
详细描述#
Query(query string, opts ...RAGSystemConfigOption) (<-chan *RAGSearchResult, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| query | string | |
| opts | ...RAGSystemConfigOption | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | <-chan *RAGSearchResult | |
| r2 | error | |
QueryDocuments#
详细描述#
_queryDocuments 在指定集合中查询文档
Example:
results, err = rag.QueryDocuments("my_collection", "query", 10)
QueryDocuments(knowledgeBaseName string, query string, limit int, opts ...rag.RAGSystemConfigOption) ([]*rag.SearchResult, error)
| 参数名 | 参数类型 | 参数解释 |
|---|
| knowledgeBaseName | string | |
| query | string | |
| limit | int | |
| opts | ...rag.RAGSystemConfigOption | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | []*rag.SearchResult | |
| r2 | error | |
aiService#
详细描述#
aiService(aiService aicommon.AICallbackType) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| aiService | aicommon.AICallbackType | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
aiServiceType#
详细描述#
aiServiceType(aiServiceName string, aiServiceConfig ...aispec.AIConfigOption) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| aiServiceName | string | |
| aiServiceConfig | ...aispec.AIConfigOption | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
buildFilter#
详细描述#
buildFilter(filter *ypb.EntityFilter) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| filter | *ypb.EntityFilter | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
buildQuery#
详细描述#
buildQuery(query string) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
chunkSize#
详细描述#
chunkSize(size int64) Option
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | Option | |
ctx#
详细描述#
ctx(ctx context.Context) AnalysisOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| ctx | context.Context | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | AnalysisOption | |
详细描述#
db(db *gorm.DB) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
docMetadata#
详细描述#
WithDocumentMetadataKeyValue sets document metadata key-value pairs
docMetadata(key string, value any) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| key | string | |
| value | any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
docRawMetadata#
详细描述#
WithDocumentRawMetadata sets raw document metadata
docRawMetadata(metadata map[string]any) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| metadata | map[string]any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
documentHandler#
详细描述#
documentHandler(documentHandler func(doc schema.VectorStoreDocument) (schema.VectorStoreDocument, error)) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| documentHandler | func(doc schema.VectorStoreDocument) (schema.VectorStoreDocument, error) | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
embeddingHandle#
详细描述#
_embeddingHandle 创建自定义嵌入处理器
Example:
embeddingOpt = rag.embeddingHandle((text) => { return [0.1, 0.2, 0.3] // 返回嵌入向量 })
embeddingHandle(handle func(text string) any) rag.RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| handle | func(text string) any | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | rag.RAGSystemConfigOption | |
entryLength#
详细描述#
entryLength(length int) RefineOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RefineOption | |
extraPrompt#
详细描述#
extraPrompt(prompt string) AnalysisOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | AnalysisOption | |
getEntityFilter#
详细描述#
getEntityFilter(reposName string, entityTypes []string, names []string, HiddenIndex []string, keywords []string) *ypb.EntityFilter
| 参数名 | 参数类型 | 参数解释 |
|---|
| reposName | string | |
| entityTypes | []string | |
| names | []string | |
| HiddenIndex | []string | |
| keywords | []string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | *ypb.EntityFilter | |
importName#
详细描述#
WithRAGCollectionName sets the specific collection name to query
importName(collectionName string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| collectionName | string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
importOverwrite#
详细描述#
importOverwrite(overwriteExisting bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| overwriteExisting | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
importRebuildGraph#
详细描述#
importRebuildGraph(rebuildHNSWIndex bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| rebuildHNSWIndex | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
khopLimit#
详细描述#
khopLimit(k int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
khopk#
详细描述#
WithKHopK 设置k-hop的跳数,k>=2时返回k-hop路径,k=0返回所有路径
khopk(k int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
khopkMax#
详细描述#
WithKHopKMax 设置最大路径长度,最小值为2
khopkMax(kMax int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
khopkMin#
详细描述#
WithKHopKMin 设置最小路径长度,最小值为2
khopkMin(kMin int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
log#
详细描述#
log(handler func(format string, args ...any)) AnalysisOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| handler | func(format string, args ...any) | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | AnalysisOption | |
noEntityRepository#
详细描述#
_noEntityRepository 禁用实体仓库
Example:
rag.noEntityRepository()
noEntityRepository() rag.RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | rag.RAGSystemConfigOption | |
noHNSWGraph#
详细描述#
noHNSWGraph(noHNSWGraph bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| noHNSWGraph | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
noKnowledgeBase#
详细描述#
_noKnowledgeBase 禁用知识库
Example:
rag.noKnowledgeBase()
noKnowledgeBase() rag.RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | rag.RAGSystemConfigOption | |
noMetadata#
详细描述#
noMetadata(noMetadata bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| noMetadata | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
noOriginInput#
详细描述#
noOriginInput(noOriginInput bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| noOriginInput | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
onlyPQCode#
详细描述#
onlyPQCode(onlyPQCode bool) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| onlyPQCode | bool | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
pathDepth#
详细描述#
pathDepth(deep int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
progressHandler#
详细描述#
progressHandler(progressHandler func(percent float64, message string, messageType string)) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| progressHandler | func(percent float64, message string, messageType string) | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryCollection#
详细描述#
WithRAGCollectionName sets the specific collection name to query
queryCollection(collectionName string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| collectionName | string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryConcurrent#
详细描述#
WithRAGConcurrent sets the concurrency level for query operations
queryConcurrent(concurrent int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryCtx#
详细描述#
WithRAGCtx sets the context for RAG query operations
queryCtx(ctx context.Context) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| ctx | context.Context | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryEnhance#
详细描述#
WithRAGEnhance sets the enhancement strategies to apply
queryEnhance(enhance ...string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| enhance | ...string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryLimit#
详细描述#
WithRAGLimit sets the maximum number of results to return
queryLimit(limit int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryScoreLimit#
详细描述#
WithRAGCollectionScoreLimit sets the score limit for collection filtering
queryScoreLimit(scoreLimit float64) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| scoreLimit | float64 | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryStatus#
详细描述#
WithRAGQueryStatus sets the query status callback function
queryStatus(callback func(label string, i any, tags ...string)) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| callback | func(label string, i any, tags ...string) | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
queryType#
详细描述#
WithRAGDocumentType sets the document type filter
queryType(documentType ...string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| documentType | ...string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragCosineDistance#
详细描述#
ragCosineDistance()
ragDescription#
详细描述#
ragDescription(description string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| description | string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragEmbeddingModel#
详细描述#
ragEmbeddingModel(model string) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragForceNew#
详细描述#
WithForceNew sets whether to force creation of new collection
ragForceNew(force bool) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragHNSWParameters#
详细描述#
WithHNSWParameters sets HNSW parameters
ragHNSWParameters(m int, ml float64, efSearch int, efConstruct int) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| m | int | |
| ml | float64 | |
| efSearch | int | |
| efConstruct | int | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragImportFile#
详细描述#
ragImportFile(importFile string) RAGSystemConfigOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| importFile | string | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
ragModelDimension#
详细描述#
WithModelDimension sets the model dimension
ragModelDimension(dimension int) RAGSystemConfigOption
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | RAGSystemConfigOption | |
statusCard#
详细描述#
statusCard(handler func(id string, data any, tags ...string)) AnalysisOption
| 参数名 | 参数类型 | 参数解释 |
|---|
| handler | func(id string, data any, tags ...string) | |
返回值#
| 返回值(顺序) | 返回值类型 | 返回值解释 |
|---|
| r1 | AnalysisOption | |