yao/kb/api/interfaces.go
Max 4ba62600dc Refactor Knowledge Base Collection Initialization and Document Retrieval
- Removed the synchronous preparation of the knowledge base (KB) collection from the InitializeConversation method, now initializing it asynchronously after user login.
- Introduced a new method, GetDocumentsContent, to retrieve content for multiple documents by their IDs, supporting text-based files and improving document handling.
- Updated the API interface to include the new GetDocumentsContent method, enhancing the document management capabilities.
- Enhanced locale handling in the login context to support user preferences during KB collection creation.
2026-01-10 12:38:42 +08:00

46 lines
2.2 KiB
Go

package api
import (
"context"
"github.com/yaoapp/gou/graphrag/types"
kbtypes "github.com/yaoapp/yao/kb/types"
)
// API defines the unified interface for all KB operations
type API interface {
// Collection operations
CreateCollection(ctx context.Context, params *CreateCollectionParams) (*CreateCollectionResult, error)
RemoveCollection(ctx context.Context, collectionID string) (*RemoveCollectionResult, error)
GetCollection(ctx context.Context, collectionID string) (map[string]interface{}, error)
CollectionExists(ctx context.Context, collectionID string) (*CollectionExistsResult, error)
ListCollections(ctx context.Context, filter *ListCollectionsFilter) (*ListCollectionsResult, error)
UpdateCollectionMetadata(ctx context.Context, collectionID string, params *UpdateMetadataParams) (*UpdateMetadataResult, error)
// Document operations
ListDocuments(ctx context.Context, filter *ListDocumentsFilter) (*ListDocumentsResult, error)
GetDocument(ctx context.Context, docID string, params *GetDocumentParams) (map[string]interface{}, error)
GetDocumentsContent(ctx context.Context, docIDs []string) ([]map[string]interface{}, error)
RemoveDocuments(ctx context.Context, params *RemoveDocumentsParams) (*RemoveDocumentsResult, error)
// Document add operations (sync)
AddFile(ctx context.Context, params *AddFileParams) (*AddDocumentResult, error)
AddText(ctx context.Context, params *AddTextParams) (*AddDocumentResult, error)
AddURL(ctx context.Context, params *AddURLParams) (*AddDocumentResult, error)
// Document add operations (async)
AddFileAsync(ctx context.Context, params *AddFileParams) (*AddDocumentAsyncResult, error)
AddTextAsync(ctx context.Context, params *AddTextParams) (*AddDocumentAsyncResult, error)
AddURLAsync(ctx context.Context, params *AddURLParams) (*AddDocumentAsyncResult, error)
// Search operations
Search(ctx context.Context, queries []Query) (*SearchResult, error)
}
// KBInstance holds the KB instance dependencies required by the API
type KBInstance struct {
GraphRag types.GraphRag // GraphRag instance
// for vector/graph operations
Config *kbtypes.Config // KB configuration
Providers *kbtypes.ProviderConfig // Provider configurations
}