Documentation
¶
Overview ¶
Package contextor provides a simple, user-friendly SDK for the Contextor knowledge management and context retrieval system.
This package serves as the main entry point for developers who want to integrate Contextor into their applications. It provides a clean, intuitive API that abstracts away the complexity of the internal services.
Basic usage:
client, err := contextor.NewClient(config) if err != nil { log.Fatal(err) } // Ingest some data result, err := client.Ingest("tenant-123", "session-456", "Important project deadline is December 31st, 2025") if err != nil { log.Fatal(err) } // Search for relevant context response, err := client.Search("tenant-123", "session-456", "What is the project deadline?") if err != nil { log.Fatal(err) } fmt.Printf("Context: %s\n", response.Context)
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) HealthCheck() error
- func (c *Client) Ingest(tenantID, sessionID, text string) (*IngestResponse, error)
- func (c *Client) IngestWithOptions(req *IngestRequest) (*IngestResponse, error)
- func (c *Client) Search(tenantID, sessionID, query string) (*SearchResponse, error)
- func (c *Client) SearchWithOptions(req *SearchRequest) (*SearchResponse, error)
- func (c *Client) StartAsyncProcessing(ctx context.Context) error
- type ClientConfig
- type IngestRequest
- type IngestResponse
- type SearchRequest
- type SearchResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main entry point for the Contextor SDK. It provides simple methods for ingesting data and searching for context.
func NewClient ¶
NewClient creates a new Contextor client with the given configuration. The config parameter can be either a JSON string or a ClientConfig struct.
func (*Client) HealthCheck ¶
HealthCheck performs a health check on all underlying services
func (*Client) Ingest ¶
func (c *Client) Ingest(tenantID, sessionID, text string) (*IngestResponse, error)
Ingest adds new text data to the knowledge base for the specified tenant and session. This operation is asynchronous - the method returns immediately with a task ID, while the actual processing happens in the background.
func (*Client) IngestWithOptions ¶
func (c *Client) IngestWithOptions(req *IngestRequest) (*IngestResponse, error)
IngestWithOptions provides more control over the ingestion process
func (*Client) Search ¶
func (c *Client) Search(tenantID, sessionID, query string) (*SearchResponse, error)
Search retrieves relevant context for the given query within the specified tenant and session.
func (*Client) SearchWithOptions ¶
func (c *Client) SearchWithOptions(req *SearchRequest) (*SearchResponse, error)
SearchWithOptions provides more control over the search process
type ClientConfig ¶
type ClientConfig struct { // Database configuration SurrealDBURL string `json:"surrealdb_url"` SurrealDBUsername string `json:"surrealdb_username,omitempty"` SurrealDBPassword string `json:"surrealdb_password,omitempty"` SurrealDBNamespace string `json:"surrealdb_namespace,omitempty"` SurrealDBDatabase string `json:"surrealdb_database,omitempty"` RedisURL string `json:"redis_url"` RedisPassword string `json:"redis_password,omitempty"` // LLM configuration OpenAIAPIKey string `json:"openai_api_key,omitempty"` OpenAIBaseURL string `json:"openai_base_url,omitempty"` OpenAIModel string `json:"openai_model,omitempty"` OpenAIEmbeddingAPIKey string `json:"openai_embedding_api_key,omitempty"` OpenAIEmbeddingModel string `json:"openai_embedding_model,omitempty"` OpenAIEmbeddingBaseURL string `json:"openai_embedding_base_url,omitempty"` OpenAIEmbeddingDimensions int `json:"openai_embedding_dimensions,omitempty"` AnthropicAPIKey string `json:"anthropic_api_key,omitempty"` AnthropicBaseURL string `json:"anthropic_base_url,omitempty"` AnthropicModel string `json:"anthropic_model,omitempty"` LLMProvider string `json:"llm_provider,omitempty"` // "openai" or "anthropic" // Optional advanced settings MaxRetries int `json:"max_retries,omitempty"` TimeoutSeconds int `json:"timeout_seconds,omitempty"` LogLevel string `json:"log_level,omitempty"` // Search configuration SearchMaxResults int `json:"search_max_results,omitempty"` SearchSimilarityThreshold float64 `json:"search_similarity_threshold,omitempty"` SearchVectorWeight float64 `json:"search_vector_weight,omitempty"` SearchBM25Weight float64 `json:"search_bm25_weight,omitempty"` SearchGraphWeight float64 `json:"search_graph_weight,omitempty"` // Context configuration ContextMaxTokens int `json:"context_max_tokens,omitempty"` ContextIncludeMetadata bool `json:"context_include_metadata,omitempty"` // Reranking configuration RerankingEnabled bool `json:"reranking_enabled,omitempty"` RerankingTopK int `json:"reranking_top_k,omitempty"` RerankingDiversityThreshold float64 `json:"reranking_diversity_threshold,omitempty"` }
ClientConfig represents the configuration for creating a new client
type IngestRequest ¶
type IngestRequest struct { TenantID string `json:"tenant_id"` SessionID string `json:"session_id,omitempty"` Text string `json:"text"` Source string `json:"source,omitempty"` Metadata map[string]interface{} `json:"metadata,omitempty"` Priority int `json:"priority,omitempty"` }
IngestRequest represents a request to ingest data
type IngestResponse ¶
type IngestResponse struct { TaskID string `json:"task_id"` Status string `json:"status"` Message string `json:"message"` Timestamp time.Time `json:"timestamp"` }
IngestResponse represents the response from an ingest operation
type SearchRequest ¶
type SearchRequest struct { TenantID string `json:"tenant_id"` SessionID string `json:"session_id,omitempty"` Query string `json:"query"` MaxResults int `json:"max_results,omitempty"` IncludeMetadata bool `json:"include_metadata,omitempty"` TimeRange *types.TimeRange `json:"time_range,omitempty"` EntityTypes []string `json:"entity_types,omitempty"` }
SearchRequest represents a request to search for context
type SearchResponse ¶
type SearchResponse struct { Context string `json:"context"` TokenCount int `json:"token_count"` EpisodeCount int `json:"episode_count"` EntityCount int `json:"entity_count"` Metadata map[string]interface{} `json:"metadata,omitempty"` }
SearchResponse represents the response from a search operation