001/*
002 *  Copyright (c) 2023-2026, Agents-Flex (fuhai999@gmail.com).
003 *  <p>
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *  <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 *  <p>
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.agentsflex.core.store;
017
018import java.util.Arrays;
019import java.util.Collection;
020import java.util.Collections;
021import java.util.List;
022
023/**
024 * Vector Store
025 *
026 * @param <T> The Vector Data
027 */
028public abstract class VectorStore<T extends VectorData> {
029
030    /**
031     * Store Vector Data
032     *
033     * @param vectorData The Vector Data
034     * @return Store Result
035     */
036    public StoreResult store(T vectorData) {
037        return store(vectorData, StoreOptions.DEFAULT);
038    }
039
040    /**
041     * Store Vector Data With Options
042     *
043     * @param vectorData The Vector Data
044     * @param options    Store Options
045     * @return Store Result
046     */
047    public StoreResult store(T vectorData, StoreOptions options) {
048        return store(Collections.singletonList(vectorData), options);
049    }
050
051    /**
052     * Store Vector Data List
053     *
054     * @param vectorDataList The Vector Data List
055     * @return Store Result
056     */
057    public StoreResult store(List<T> vectorDataList) {
058        return store(vectorDataList, StoreOptions.DEFAULT);
059    }
060
061    /**
062     * Store Vector Data list wit options
063     *
064     * @param vectorDataList vector data list
065     * @param options        options
066     * @return store result
067     */
068    public abstract StoreResult store(List<T> vectorDataList, StoreOptions options);
069
070
071    /**
072     * delete store data by ids
073     *
074     * @param ids the data ids
075     * @return store result
076     */
077    public StoreResult delete(String... ids) {
078        return delete(Arrays.asList(ids), StoreOptions.DEFAULT);
079    }
080
081
082    /**
083     * delete store data by ids
084     *
085     * @param ids the data ids
086     * @return store result
087     */
088    public StoreResult delete(Number... ids) {
089        return delete(Arrays.asList(ids), StoreOptions.DEFAULT);
090    }
091
092
093    /**
094     * delete store data by id collection
095     *
096     * @param ids the ids
097     * @return store result
098     */
099    public StoreResult delete(Collection<?> ids) {
100        return delete(ids, StoreOptions.DEFAULT);
101    }
102
103    /**
104     * delete store data by ids with options
105     *
106     * @param ids     ids
107     * @param options store options
108     * @return store result
109     */
110    public abstract StoreResult delete(Collection<?> ids, StoreOptions options);
111
112    /**
113     * update the vector data by id
114     *
115     * @param vectorData the vector data
116     * @return store result
117     */
118    public StoreResult update(T vectorData) {
119        return update(vectorData, StoreOptions.DEFAULT);
120    }
121
122
123    /**
124     * update the vector data by id with options
125     *
126     * @param vectorData vector data
127     * @param options    store options
128     * @return store result
129     */
130    public StoreResult update(T vectorData, StoreOptions options) {
131        return update(Collections.singletonList(vectorData), options);
132    }
133
134    /**
135     * update vector data list
136     *
137     * @param vectorDataList vector data list
138     * @return store result
139     */
140    public StoreResult update(List<T> vectorDataList) {
141        return update(vectorDataList, StoreOptions.DEFAULT);
142    }
143
144    /**
145     * update store data list with options
146     *
147     * @param vectorDataList vector data list
148     * @param options        store options
149     * @return store result
150     */
151    public abstract StoreResult update(List<T> vectorDataList, StoreOptions options);
152
153    /**
154     * search vector data by SearchWrapper
155     *
156     * @param wrapper SearchWrapper
157     * @return the vector data list
158     */
159    public List<T> search(SearchWrapper wrapper) {
160        return search(wrapper, StoreOptions.DEFAULT);
161    }
162
163
164    /**
165     * search vector data by SearchWrapper with options
166     *
167     * @param wrapper SearchWrapper
168     * @param options Store Options
169     * @return the vector data list
170     */
171    public abstract List<T> search(SearchWrapper wrapper, StoreOptions options);
172}