20250408 增加向量数据库milvus配置,将知识库内容向量化后保存到milvus中
This commit is contained in:
parent
228fb4a94e
commit
eb9c01e74e
11
pom.xml
11
pom.xml
@ -56,6 +56,17 @@
|
||||
<version>1.0.0-beta1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-milvus</artifactId>
|
||||
<version>1.0.0-beta1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-embeddings-all-minilm-l6-v2</artifactId>
|
||||
<version>1.0.0-beta1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-community-dashscope-spring-boot-starter</artifactId>
|
||||
|
@ -39,15 +39,10 @@ public class AssistantInit {
|
||||
ChatLanguageModel qwenModel = QwenChatModel.builder()
|
||||
.apiKey(apiKey)
|
||||
.modelName(model)
|
||||
.build();
|
||||
List<Document> documents = FileSystemDocumentLoader.loadDocuments(ragPath);
|
||||
// for simplicity, we will use an in-memory one:
|
||||
InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
|
||||
EmbeddingStoreIngestor.ingest(documents, embeddingStore);
|
||||
.build();// for simplicity, we will use an in-memory one:
|
||||
return AiServices.builder(Assist.class)
|
||||
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
|
||||
.chatLanguageModel(qwenModel)
|
||||
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
|
||||
// .tools(new MyCalculator())
|
||||
.build();
|
||||
}
|
||||
|
@ -13,7 +13,11 @@ import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.rag.content.retriever.ContentRetriever;
|
||||
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
|
||||
import dev.langchain4j.service.AiServices;
|
||||
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
|
||||
import dev.langchain4j.store.embedding.EmbeddingStore;
|
||||
import dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore;
|
||||
import io.milvus.common.clientenum.ConsistencyLevelEnum;
|
||||
import io.milvus.param.IndexType;
|
||||
import io.milvus.param.MetricType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -41,7 +45,21 @@ public class SegmentConfig {
|
||||
.modelName(model)
|
||||
.build();
|
||||
QwenEmbeddingModel embeddingModel = QwenEmbeddingModel.builder().apiKey(apiKey).build();
|
||||
InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
|
||||
// InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
|
||||
EmbeddingStore<TextSegment> embeddingStore = MilvusEmbeddingStore.builder()
|
||||
.host("localhost")
|
||||
.port(19530)
|
||||
.collectionName("langchain4j_collection")
|
||||
.dimension(1536)
|
||||
.indexType(IndexType.FLAT)
|
||||
.metricType(MetricType.COSINE)
|
||||
.consistencyLevel(ConsistencyLevelEnum.EVENTUALLY)
|
||||
.autoFlushOnInsert(true)
|
||||
.idFieldName("id")
|
||||
.textFieldName("text")
|
||||
.metadataFieldName("metadata")
|
||||
.vectorFieldName("vector")
|
||||
.build();
|
||||
List<Document> documents = FileSystemDocumentLoader.loadDocuments(ragPath);
|
||||
for (Document document : documents) {
|
||||
DocumentByLineSplitter splitter = new DocumentByLineSplitter(300,30);
|
||||
|
@ -95,7 +95,7 @@ public class LangChainController {
|
||||
@GetMapping("/embedd/chat")
|
||||
public String embeddChat(@RequestParam("input") String input) {
|
||||
System.out.println("start embedd chat...");
|
||||
embeddingService.embedding(input);
|
||||
// embeddingService.embedding(input);
|
||||
return segmentAssist.chat(input);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user