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 com.agentsflex.core.model.embedding.EmbeddingOptions;
019import com.agentsflex.core.util.Metadata;
020import com.agentsflex.core.util.StringUtil;
021
022import java.util.ArrayList;
023import java.util.Collections;
024import java.util.List;
025
026/**
027 * Store Options, Each store can have its own Options implementation.
028 */
029public class StoreOptions extends Metadata {
030
031    public static final StoreOptions DEFAULT = new StoreOptions() {
032        @Override
033        public void setCollectionName(String collectionName) {
034            throw new IllegalStateException("Can not set collectionName to the default instance.");
035        }
036
037        @Override
038        public void setPartitionNames(List<String> partitionNames) {
039            throw new IllegalStateException("Can not set partitionName to the default instance.");
040        }
041
042        @Override
043        public void setEmbeddingOptions(EmbeddingOptions embeddingOptions) {
044            throw new IllegalStateException("Can not set embeddingOptions to the default instance.");
045        }
046    };
047
048    /**
049     * store collection name
050     */
051    private String collectionName;
052
053    /**
054     * store index name
055     */
056    private String indexName;
057
058    /**
059     * store partition name
060     */
061    private List<String> partitionNames;
062
063    /**
064     * store embedding options
065     */
066    private EmbeddingOptions embeddingOptions = EmbeddingOptions.DEFAULT;
067
068
069    public String getCollectionName() {
070        return collectionName;
071    }
072
073    public String getCollectionNameOrDefault(String other) {
074        return StringUtil.hasText(collectionName) ? collectionName : other;
075    }
076
077    public void setCollectionName(String collectionName) {
078        this.collectionName = collectionName;
079    }
080
081    public List<String> getPartitionNames() {
082        return partitionNames;
083    }
084
085    public String getPartitionName() {
086        return partitionNames != null && !partitionNames.isEmpty() ? partitionNames.get(0) : null;
087    }
088
089    public List<String> getPartitionNamesOrEmpty() {
090        return partitionNames == null ? Collections.emptyList() : partitionNames;
091    }
092
093    public void setPartitionNames(List<String> partitionNames) {
094        this.partitionNames = partitionNames;
095    }
096
097    public StoreOptions partitionName(String partitionName) {
098        if (this.partitionNames == null) {
099            this.partitionNames = new ArrayList<>(1);
100        }
101        this.partitionNames.add(partitionName);
102        return this;
103    }
104
105
106    public EmbeddingOptions getEmbeddingOptions() {
107        return embeddingOptions;
108    }
109
110    public void setEmbeddingOptions(EmbeddingOptions embeddingOptions) {
111        this.embeddingOptions = embeddingOptions;
112    }
113
114
115    public static StoreOptions ofCollectionName(String collectionName) {
116        StoreOptions storeOptions = new StoreOptions();
117        storeOptions.setCollectionName(collectionName);
118        return storeOptions;
119    }
120
121    public String getIndexName() {
122        return indexName;
123    }
124
125    public void setIndexName(String indexName) {
126        this.indexName = indexName;
127    }
128
129    public String getIndexNameOrDefault(String other) {
130        return StringUtil.hasText(indexName) ? indexName : other;
131    }
132}