feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package searchstore
import "fmt"
type DSL struct {
Op Op
Field string
Value interface{} // builtin types / []*DSL
}
type Op string
const (
OpEq Op = "eq"
OpNe Op = "ne"
OpLike Op = "like"
OpIn Op = "in"
OpAnd Op = "and"
OpOr Op = "or"
)
func (d *DSL) DSL() map[string]any {
return map[string]any{"dsl": d}
}
func LoadDSL(src map[string]any) (*DSL, error) {
if src == nil {
return nil, nil
}
dsl, ok := src["dsl"].(*DSL)
if !ok {
return nil, fmt.Errorf("load dsl failed")
}
return dsl, nil
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package searchstore
import (
"context"
)
type Manager interface {
Create(ctx context.Context, req *CreateRequest) error
Drop(ctx context.Context, req *DropRequest) error
GetType() SearchStoreType
GetSearchStore(ctx context.Context, collectionName string) (SearchStore, error)
}
type CreateRequest struct {
CollectionName string
Fields []*Field
CollectionMeta map[string]string
}
type DropRequest struct {
CollectionName string
}
type GetSearchStoreRequest struct {
CollectionName string
}
type Field struct {
Name FieldName
Type FieldType
Description string
Nullable bool
IsPrimary bool
Indexing bool
}
type SearchStoreType string
const (
TypeVectorStore SearchStoreType = "vector"
TypeTextStore SearchStoreType = "text"
)
type FieldName = string
// 内置 field name
const (
FieldID FieldName = "id" // int64
FieldCreatorID FieldName = "creator_id" // int64
FieldTextContent FieldName = "text_content" // string
)
type FieldType int64
const (
FieldTypeUnknown FieldType = 0
FieldTypeInt64 FieldType = 1
FieldTypeText FieldType = 2
FieldTypeDenseVector FieldType = 3
FieldTypeSparseVector FieldType = 4
)

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package searchstore
import (
"github.com/cloudwego/eino/components/indexer"
"github.com/cloudwego/eino/components/retriever"
"github.com/coze-dev/coze-studio/backend/infra/contract/document/progressbar"
)
type IndexerOptions struct {
PartitionKey *string
Partition *string // 存储分片映射
IndexingFields []string
ProgressBar progressbar.ProgressBar
}
type RetrieverOptions struct {
MultiMatch *MultiMatch // 多 field 查询
PartitionKey *string
Partitions []string // 查询分片映射
}
type MultiMatch struct {
Fields []string
Query string
}
func WithIndexerPartitionKey(key string) indexer.Option {
return indexer.WrapImplSpecificOptFn(func(o *IndexerOptions) {
o.PartitionKey = &key
})
}
func WithPartition(partition string) indexer.Option {
return indexer.WrapImplSpecificOptFn(func(o *IndexerOptions) {
o.Partition = &partition
})
}
func WithIndexingFields(fields []string) indexer.Option {
return indexer.WrapImplSpecificOptFn(func(o *IndexerOptions) {
o.IndexingFields = fields
})
}
func WithProgressBar(progressBar progressbar.ProgressBar) indexer.Option {
return indexer.WrapImplSpecificOptFn(func(o *IndexerOptions) {
o.ProgressBar = progressBar
})
}
func WithMultiMatch(fields []string, query string) retriever.Option {
return retriever.WrapImplSpecificOptFn(func(o *RetrieverOptions) {
o.MultiMatch = &MultiMatch{
Fields: fields,
Query: query,
}
})
}
func WithRetrieverPartitionKey(key string) retriever.Option {
return retriever.WrapImplSpecificOptFn(func(o *RetrieverOptions) {
o.PartitionKey = &key
})
}
func WithPartitions(partitions []string) retriever.Option {
return retriever.WrapImplSpecificOptFn(func(o *RetrieverOptions) {
o.Partitions = partitions
})
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package searchstore
import (
"context"
"github.com/cloudwego/eino/components/indexer"
"github.com/cloudwego/eino/components/retriever"
)
type SearchStore interface {
indexer.Indexer
retriever.Retriever
Delete(ctx context.Context, ids []string) error
}