|
| 1 | +// Copyright (c) KAITO authors. |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +package v1beta1 |
| 15 | + |
| 16 | +import ( |
| 17 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 18 | +) |
| 19 | + |
| 20 | +type StorageSpec struct { |
| 21 | + // PersistentVolumeClaim specifies the PVC to use for persisting vector database data. |
| 22 | + // If not specified, an emptyDir will be used (data will be lost on pod restart). |
| 23 | + // +optional |
| 24 | + PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"` |
| 25 | + // MountPath specifies where the volume should be mounted in the container. |
| 26 | + // Defaults to /mnt/data if not specified. |
| 27 | + // +optional |
| 28 | + MountPath string `json:"mountPath,omitempty"` |
| 29 | +} |
| 30 | + |
| 31 | +type RemoteEmbeddingSpec struct { |
| 32 | + // URL points to a publicly available embedding service, such as OpenAI. |
| 33 | + URL string `json:"url"` |
| 34 | + // AccessSecret is the name of the secret that contains the service access token. |
| 35 | + // +optional |
| 36 | + AccessSecret string `json:"accessSecret,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +type LocalEmbeddingSpec struct { |
| 40 | + // Image is the name of the containerized embedding model image. |
| 41 | + // +optional |
| 42 | + Image string `json:"image,omitempty"` |
| 43 | + // +optional |
| 44 | + ImagePullSecret string `json:"imagePullSecret,omitempty"` |
| 45 | + // ModelID is the ID of the embedding model hosted by huggingface, e.g., BAAI/bge-small-en-v1.5. |
| 46 | + // When this field is specified, the RAG engine will download the embedding model |
| 47 | + // from huggingface repository during startup. The embedding model will not persist in local storage. |
| 48 | + // Note that if Image is specified, ModelID should not be specified and vice versa. |
| 49 | + // +optional |
| 50 | + ModelID string `json:"modelID,omitempty"` |
| 51 | + // ModelAccessSecret is the name of the secret that contains the huggingface access token. |
| 52 | + // +optional |
| 53 | + ModelAccessSecret string `json:"modelAccessSecret,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +type EmbeddingSpec struct { |
| 57 | + // Remote specifies how to generate embeddings for index data using a remote service. |
| 58 | + // Note that either Remote or Local needs to be specified, not both. |
| 59 | + // +optional |
| 60 | + Remote *RemoteEmbeddingSpec `json:"remote,omitempty"` |
| 61 | + // Local specifies how to generate embeddings for index data using a model run locally. |
| 62 | + // +optional |
| 63 | + Local *LocalEmbeddingSpec `json:"local,omitempty"` |
| 64 | +} |
| 65 | + |
| 66 | +type InferenceServiceSpec struct { |
| 67 | + // URL points to a running inference service endpoint which accepts http(s) payload. |
| 68 | + URL string `json:"url"` |
| 69 | + // AccessSecret is the name of the secret that contains the service access token. |
| 70 | + // +optional |
| 71 | + AccessSecret string `json:"accessSecret,omitempty"` |
| 72 | + // ContextWindowSize defines the combined maximum of input and output tokens that can be handled by the LLM in a single request. |
| 73 | + // This value is critical for accurately managing how much of the original query and supporting documents |
| 74 | + // (retrieved via RAG) can be included in the prompt without exceeding the model's input limit. |
| 75 | + // |
| 76 | + // It is used to determine how much space is available for retrieved documents after accounting for the query, |
| 77 | + // system prompts, formatting tokens, and any other fixed prompt components. |
| 78 | + // |
| 79 | + // Setting this value correctly is essential for ensuring that the RAG system does not truncate important |
| 80 | + // context or exceed model limits, which can lead to degraded response quality or inference errors. |
| 81 | + // |
| 82 | + // Must match the token limit of the LLM backend being used (e.g., 8096, 16384, 32768 tokens). |
| 83 | + ContextWindowSize int `json:"contextWindowSize"` |
| 84 | +} |
| 85 | + |
| 86 | +type RAGEngineSpec struct { |
| 87 | + // Compute specifies the dedicated GPU resource used by an embedding model running locally if required. |
| 88 | + // +optional |
| 89 | + Compute *ResourceSpec `json:"compute,omitempty"` |
| 90 | + // Storage specifies how to access the vector database used to save the embedding vectors. |
| 91 | + // If this field is not specified, by default, an in-memory vector DB will be used. |
| 92 | + // The data will not be persisted. |
| 93 | + // +optional |
| 94 | + Storage *StorageSpec `json:"storage,omitempty"` |
| 95 | + // Embedding specifies whether the RAG engine generates embedding vectors using a remote service |
| 96 | + // or using a embedding model running locally. |
| 97 | + Embedding *EmbeddingSpec `json:"embedding"` |
| 98 | + InferenceService *InferenceServiceSpec `json:"inferenceService"` |
| 99 | + // QueryServiceName is the name of the service which exposes the endpoint for accepting user queries to the |
| 100 | + // inference service. If not specified, a default service name will be created by the RAG engine. |
| 101 | + // +optional |
| 102 | + QueryServiceName string `json:"queryServiceName,omitempty"` |
| 103 | + // IndexServiceName is the name of the service which exposes the endpoint for user to input the index data |
| 104 | + // to generate embeddings. If not specified, a default service name will be created by the RAG engine. |
| 105 | + // +optional |
| 106 | + IndexServiceName string `json:"indexServiceName,omitempty"` |
| 107 | +} |
| 108 | + |
| 109 | +// RAGEngineStatus defines the observed state of RAGEngine |
| 110 | +type RAGEngineStatus struct { |
| 111 | + // WorkerNodes is the list of nodes chosen to run the workload based on the RAGEngine resource requirement. |
| 112 | + // +optional |
| 113 | + WorkerNodes []string `json:"workerNodes,omitempty"` |
| 114 | + |
| 115 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 116 | +} |
| 117 | + |
| 118 | +// RAGEngine is the Schema for the ragengine API |
| 119 | +// +kubebuilder:object:root=true |
| 120 | +// +kubebuilder:subresource:status |
| 121 | +// +kubebuilder:resource:path=ragengines,scope=Namespaced,categories=ragengine,shortName=rag |
| 122 | +// +kubebuilder:storageversion |
| 123 | +// +kubebuilder:printcolumn:name="Instance",type="string",JSONPath=".spec.compute.instanceType",description="" |
| 124 | +// +kubebuilder:printcolumn:name="ResourceReady",type="string",JSONPath=".status.conditions[?(@.type==\"ResourceReady\")].status",description="" |
| 125 | +// +kubebuilder:printcolumn:name="ServiceReady",type="string",JSONPath=".status.conditions[?(@.type==\"ServiceReady\")].status",description="" |
| 126 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="" |
| 127 | +type RAGEngine struct { |
| 128 | + metav1.TypeMeta `json:",inline"` |
| 129 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 130 | + |
| 131 | + Spec *RAGEngineSpec `json:"spec,omitempty"` |
| 132 | + |
| 133 | + Status RAGEngineStatus `json:"status,omitempty"` |
| 134 | +} |
| 135 | + |
| 136 | +// RAGEngineList contains a list of RAGEngine |
| 137 | +// +kubebuilder:object:root=true |
| 138 | +type RAGEngineList struct { |
| 139 | + metav1.TypeMeta `json:",inline"` |
| 140 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 141 | + Items []RAGEngine `json:"items"` |
| 142 | +} |
| 143 | + |
| 144 | +func init() { |
| 145 | + SchemeBuilder.Register(&RAGEngine{}, &RAGEngineList{}) |
| 146 | +} |
0 commit comments