|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.flink.table.connector.source; |
| 20 | + |
| 21 | +import org.apache.flink.annotation.PublicEvolving; |
| 22 | +import org.apache.flink.configuration.ReadableConfig; |
| 23 | +import org.apache.flink.table.connector.source.search.AsyncVectorSearchFunctionProvider; |
| 24 | +import org.apache.flink.table.connector.source.search.VectorSearchFunctionProvider; |
| 25 | +import org.apache.flink.types.RowKind; |
| 26 | + |
| 27 | +import java.io.Serializable; |
| 28 | + |
| 29 | +/** |
| 30 | + * A {@link DynamicTableSource} that searches rows of an external storage system by one or more |
| 31 | + * vectors during runtime. |
| 32 | + * |
| 33 | + * <p>Compared to {@link ScanTableSource}, the source does not have to read the entire table and can |
| 34 | + * lazily fetch individual values from a (possibly continuously changing) external table when |
| 35 | + * necessary. |
| 36 | + * |
| 37 | + * <p>Note: Compared to {@link ScanTableSource}, a {@link VectorSearchTableSource} only supports |
| 38 | + * emitting insert-only changes (see also {@link RowKind}). |
| 39 | + * |
| 40 | + * <p>In the last step, the planner will call {@link #getSearchRuntimeProvider(VectorSearchContext)} |
| 41 | + * to obtain a provider of runtime implementation. The search fields that are required to perform a |
| 42 | + * search are derived from a query by the planner and will be provided in the given {@link |
| 43 | + * VectorSearchTableSource.VectorSearchContext#getSearchColumns()}. The values for those search |
| 44 | + * fields are passed at runtime. |
| 45 | + */ |
| 46 | +@PublicEvolving |
| 47 | +public interface VectorSearchTableSource extends DynamicTableSource { |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns a {@code VectorSearchRuntimeProvider}. VectorSearchRuntimeProvider is a base |
| 51 | + * interface that should be extended (is this true) by child interfaces for specialized vector |
| 52 | + * searches. |
| 53 | + * |
| 54 | + * <p>There exist different interfaces for runtime implementation which is why {@link |
| 55 | + * VectorSearchRuntimeProvider} serves as the base interface. |
| 56 | + * |
| 57 | + * <p>Independent of the provider interface, a source implementation can work on either |
| 58 | + * arbitrary objects or internal data structures (see {@link org.apache.flink.table.data} for |
| 59 | + * more information). |
| 60 | + * |
| 61 | + * <p>The given {@link VectorSearchContext} offers utilities for the planner to create runtime |
| 62 | + * implementation with minimal dependencies to internal data structures. |
| 63 | + * |
| 64 | + * @see VectorSearchFunctionProvider |
| 65 | + * @see AsyncVectorSearchFunctionProvider |
| 66 | + */ |
| 67 | + VectorSearchRuntimeProvider getSearchRuntimeProvider(VectorSearchContext context); |
| 68 | + |
| 69 | + // -------------------------------------------------------------------------------------------- |
| 70 | + // Helper interfaces |
| 71 | + // -------------------------------------------------------------------------------------------- |
| 72 | + |
| 73 | + /** |
| 74 | + * Context for creating runtime implementation via a {@link VectorSearchRuntimeProvider}. |
| 75 | + * |
| 76 | + * <p>It offers utilities for the planner to create runtime implementation with minimal |
| 77 | + * dependencies to internal data structures. |
| 78 | + * |
| 79 | + * <p>Methods should be called in {@link #getSearchRuntimeProvider(VectorSearchContext)}. |
| 80 | + * Returned instances that are {@link Serializable} can be directly passed into the runtime |
| 81 | + * implementation class. |
| 82 | + */ |
| 83 | + @PublicEvolving |
| 84 | + interface VectorSearchContext extends DynamicTableSource.Context { |
| 85 | + |
| 86 | + /** |
| 87 | + * Returns an array of key index paths that should be used during the search. The indices |
| 88 | + * are 0-based and support composite keys within (possibly nested) structures. |
| 89 | + * |
| 90 | + * <p>For example, given a table with data type {@code ROW < i INT, s STRING, r ROW < i2 |
| 91 | + * INT, s2 STRING > >}, this method would return {@code [[0], [2, 1]]} when {@code i} and |
| 92 | + * {@code s2} are used for performing a lookup. |
| 93 | + * |
| 94 | + * @return array of key index paths |
| 95 | + */ |
| 96 | + int[][] getSearchColumns(); |
| 97 | + |
| 98 | + /** |
| 99 | + * Runtime config provided to the provider. The config can be used by the planner or vector |
| 100 | + * search provider at runtime. For example, async options can be used by planner to choose |
| 101 | + * async inference. Other config such as http timeout or retry can be used to configure |
| 102 | + * search functions. |
| 103 | + */ |
| 104 | + ReadableConfig runtimeConfig(); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Provides actual runtime implementation for reading the data. |
| 109 | + * |
| 110 | + * <p>There exists different interfaces for runtime implementation which is why {@link |
| 111 | + * VectorSearchRuntimeProvider} serves as the base interface. |
| 112 | + * |
| 113 | + * @see VectorSearchFunctionProvider |
| 114 | + * @see AsyncVectorSearchFunctionProvider |
| 115 | + */ |
| 116 | + @PublicEvolving |
| 117 | + interface VectorSearchRuntimeProvider {} |
| 118 | +} |
0 commit comments