Documentation
¶
Index ¶
- Constants
- Variables
- type AliyunHandler
- func (h *AliyunHandler) Delete(ctx context.Context, ids []string, options *DeleteOptions) error
- func (h *AliyunHandler) Get(ctx context.Context, ids []string, options *GetOptions) ([]Record, error)
- func (h *AliyunHandler) List(ctx context.Context, options *ListOptions) (*ListResult, error)
- func (h *AliyunHandler) Provider() string
- func (h *AliyunHandler) Query(ctx context.Context, text string, options *QueryOptions) ([]QueryResult, error)
- func (h *AliyunHandler) Upsert(ctx context.Context, records []Record, options *UpsertOptions) error
- type AliyunOptions
- type Chunk
- type ChunkOptions
- type Chunker
- type DeleteOptions
- type Embedder
- type FactoryOptions
- type GetOptions
- type KnowledgeHandler
- type KnowledgeProvider
- type LLMChunker
- type ListOptions
- type ListResult
- type NvidiaEmbedClient
- type QdrantHandler
- func (qh *QdrantHandler) Delete(ctx context.Context, ids []string, options *DeleteOptions) error
- func (qh *QdrantHandler) Get(ctx context.Context, ids []string, options *GetOptions) ([]Record, error)
- func (qh *QdrantHandler) List(ctx context.Context, options *ListOptions) (*ListResult, error)
- func (qh *QdrantHandler) Provider() string
- func (qh *QdrantHandler) Query(ctx context.Context, text string, options *QueryOptions) ([]QueryResult, error)
- func (qh *QdrantHandler) Upsert(ctx context.Context, records []Record, options *UpsertOptions) error
- type QdrantOptions
- type QueryOptions
- type QueryResult
- type Record
- type RerankResult
- type SiliconFlowRerankClient
- type UpsertOptions
Constants ¶
const ( // KnowledgeAliyun Aliyun Bailian Knowledge Base KnowledgeAliyun = "aliyun" // KnowledgeQdrant Qdrant Vector Database KnowledgeQdrant = "qdrant" )
const (
// DefaultBailianEndpoint is the public Bailian OpenAPI host (Beijing region).
DefaultBailianEndpoint = "bailian.cn-beijing.aliyuncs.com"
)
Variables ¶
var ErrEmptyText = errors.New("empty text")
var ErrUnsupportedKnowledgeProvider = errors.New("unsupported knowledge provider")
Functions ¶
This section is empty.
Types ¶
type AliyunHandler ¶
type AliyunHandler struct {
WorkspaceID string
IndexID string
// contains filtered or unexported fields
}
AliyunHandler calls Alibaba Cloud Model Studio (百炼) knowledge-base OpenAPI. Credentials are AccessKey ID/Secret (main or RAM user with Bailian data permissions).
Index selection: AliyunOptions.IndexID is the default knowledge base id. Per-call options.Namespace (UpsertOptions, QueryOptions, …) overrides IndexID when set.
Upsert: submits SubmitIndexAddDocumentsJob. Each Record must reference an existing Data Center document id in Record.ID or metadata keys document_id / bailian_document_id.
Query: maps to Retrieve (server-side dense retrieval + rerank). No local Embedder.
List: ListIndexDocuments; ListOptions.Offset is a 1-based page number string.
Get: scans ListIndexDocuments pages until all requested ids are found (bounded pages).
func (*AliyunHandler) Delete ¶
func (h *AliyunHandler) Delete(ctx context.Context, ids []string, options *DeleteOptions) error
func (*AliyunHandler) Get ¶
func (h *AliyunHandler) Get(ctx context.Context, ids []string, options *GetOptions) ([]Record, error)
func (*AliyunHandler) List ¶
func (h *AliyunHandler) List(ctx context.Context, options *ListOptions) (*ListResult, error)
func (*AliyunHandler) Provider ¶
func (h *AliyunHandler) Provider() string
func (*AliyunHandler) Query ¶
func (h *AliyunHandler) Query(ctx context.Context, text string, options *QueryOptions) ([]QueryResult, error)
func (*AliyunHandler) Upsert ¶
func (h *AliyunHandler) Upsert(ctx context.Context, records []Record, options *UpsertOptions) error
type AliyunOptions ¶
type AliyunOptions struct {
AccessKeyID string
AccessKeySecret string
// Endpoint defaults to DefaultBailianEndpoint (Beijing public endpoint).
Endpoint string
// RegionID defaults to cn-beijing when Endpoint is empty.
RegionID string
// WorkspaceID is the business space id from the Bailian console.
WorkspaceID string
// IndexID is the knowledge base id (CreateIndex / console).
IndexID string
}
AliyunOptions configures Alibaba Cloud Model Studio (百炼) knowledge access. Use AccessKey pair with Bailian data permissions (e.g. AliyunBailianDataFullAccess for RAM users).
type ChunkOptions ¶
type ChunkOptions struct {
MaxChars int
OverlapChars int
MinChars int
DocumentTitle string
// PreChunkClean is passed to utils.CleanText before the LLM call (UTF-8 repair, optional markdown strip, etc.).
// If nil, StripMarkdown and DedupLines are enabled so code fences / mermaid are less likely to break JSON output.
PreChunkClean *utils.Options
}
type Chunker ¶
type Chunker interface {
Provider() string
Chunk(ctx context.Context, text string, opts *ChunkOptions) ([]Chunk, error)
}
Chunker splits long text into chunks (implementations may use an LLM).
type DeleteOptions ¶
type DeleteOptions struct {
Namespace string
}
type FactoryOptions ¶
type FactoryOptions struct {
Qdrant *QdrantOptions
Aliyun *AliyunOptions
}
type GetOptions ¶
type GetOptions struct {
Namespace string
}
type KnowledgeHandler ¶
type KnowledgeHandler interface {
Provider() string
Upsert(ctx context.Context, records []Record, options *UpsertOptions) error
Query(ctx context.Context, text string, options *QueryOptions) ([]QueryResult, error)
Get(ctx context.Context, ids []string, options *GetOptions) ([]Record, error)
List(ctx context.Context, options *ListOptions) (*ListResult, error)
Delete(ctx context.Context, ids []string, options *DeleteOptions) error
}
func New ¶
func New(provider string, opts *FactoryOptions) (KnowledgeHandler, error)
type KnowledgeProvider ¶
type KnowledgeProvider string
KnowledgeProvider common provider type
func (KnowledgeProvider) ToString ¶
func (kp KnowledgeProvider) ToString() string
ToString toString for llm
type LLMChunker ¶
type LLMChunker struct {
LLM llm.LLMHandler
Model string
}
LLMChunker asks an LLM to return a JSON array of chunks.
func (*LLMChunker) Chunk ¶
func (c *LLMChunker) Chunk(ctx context.Context, text string, opts *ChunkOptions) ([]Chunk, error)
func (*LLMChunker) Provider ¶
func (c *LLMChunker) Provider() string
type ListOptions ¶
type ListResult ¶
type NvidiaEmbedClient ¶
type QdrantHandler ¶
type QdrantHandler struct {
BaseURL string
APIKey string
Collection string
HTTPClient *http.Client
Embedder Embedder
}
func (*QdrantHandler) Delete ¶
func (qh *QdrantHandler) Delete(ctx context.Context, ids []string, options *DeleteOptions) error
func (*QdrantHandler) Get ¶
func (qh *QdrantHandler) Get(ctx context.Context, ids []string, options *GetOptions) ([]Record, error)
func (*QdrantHandler) List ¶
func (qh *QdrantHandler) List(ctx context.Context, options *ListOptions) (*ListResult, error)
func (*QdrantHandler) Provider ¶
func (qh *QdrantHandler) Provider() string
func (*QdrantHandler) Query ¶
func (qh *QdrantHandler) Query(ctx context.Context, text string, options *QueryOptions) ([]QueryResult, error)
func (*QdrantHandler) Upsert ¶
func (qh *QdrantHandler) Upsert(ctx context.Context, records []Record, options *UpsertOptions) error
type QdrantOptions ¶
type QueryResult ¶
type RerankResult ¶
type SiliconFlowRerankClient ¶
type SiliconFlowRerankClient struct {
BaseURL string
APIKey string
Model string
HTTPClient *http.Client
}
func (*SiliconFlowRerankClient) Rerank ¶
func (c *SiliconFlowRerankClient) Rerank(ctx context.Context, query string, documents []string, topN int) ([]RerankResult, error)