Skip to content

Commit 942e559

Browse files
committed
feat: add splitter
1 parent 7d75534 commit 942e559

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright 2023 Sven Loesekann
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package ch.xxx.aidoclibchat.adapter.config;
14+
15+
import org.springframework.ai.embedding.EmbeddingModel;
16+
import org.springframework.ai.transformers.TransformersEmbeddingModel;
17+
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
18+
import org.springframework.context.annotation.Bean;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.jdbc.core.JdbcTemplate;
21+
22+
//@Configuration
23+
public class EmbeddingConfig {
24+
25+
@Bean
26+
public EmbeddingModel embeddingModel() throws Exception {
27+
// 1. Raw ONNX Modell laden
28+
TransformersEmbeddingModel onnxModel = new TransformersEmbeddingModel();
29+
onnxModel.setTokenizerResource("classpath:/models/tokenizer.json");
30+
onnxModel.setModelResource("classpath:/models/model.onnx");
31+
onnxModel.afterPropertiesSet();
32+
33+
// 2. Mit unserem 2000er-Slicer dekorieren
34+
return new Qwen3TruncatingEmbeddingModel(onnxModel);
35+
}
36+
37+
@Bean
38+
public PgVectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
39+
return PgVectorStore.builder(jdbcTemplate, embeddingModel)
40+
.dimensions(2000) // Optional: Falls das Modell die Dimensionen nicht automatisch meldet, hier festlegen
41+
.build();
42+
}
43+
}
44+

0 commit comments

Comments
 (0)