Skip to content

Commit

Permalink
fix: embedding error
Browse files Browse the repository at this point in the history
  • Loading branch information
TyCoding committed Nov 15, 2024
1 parent bfe3ca0 commit 03cb500
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ public List<EmbeddingR> embeddingDocs(ChatReq req) {
}
document.metadata().put(KNOWLEDGE, req.getKnowledgeId()).put(FILENAME, req.getDocsName());

DocumentSplitter splitter = EmbeddingProvider.splitter(req.getModelName(), req.getModelProvider());
List<TextSegment> segments = splitter.split(document);
List<EmbeddingR> list = new ArrayList<>();
try {
DocumentSplitter splitter = EmbeddingProvider.splitter(req.getModelName(), req.getModelProvider());
List<TextSegment> segments = splitter.split(document);

EmbeddingModel embeddingModel = embeddingProvider.getEmbeddingModel(req.getKnowledgeId());
EmbeddingStore<TextSegment> embeddingStore = embeddingProvider.getEmbeddingStore(req.getKnowledgeId());
List<Embedding> embeddings = embeddingModel.embedAll(segments).content();
List<String> ids = embeddingStore.addAll(embeddings, segments);
EmbeddingModel embeddingModel = embeddingProvider.getEmbeddingModel(req.getKnowledgeId());
EmbeddingStore<TextSegment> embeddingStore = embeddingProvider.getEmbeddingStore(req.getKnowledgeId());
List<Embedding> embeddings = embeddingModel.embedAll(segments).content();
List<String> ids = embeddingStore.addAll(embeddings, segments);

List<EmbeddingR> list = new ArrayList<>();
for (int i = 0; i < ids.size(); i++) {
list.add(new EmbeddingR().setVectorId(ids.get(i)).setText(segments.get(i).text()));
for (int i = 0; i < ids.size(); i++) {
list.add(new EmbeddingR().setVectorId(ids.get(i)).setText(segments.get(i).text()));
}
} catch (Exception e) {
e.printStackTrace();
}

log.info(">>>>>>>>>>>>>> Docs文档向量解析结束,KnowledgeId={}, DocsName={}", req.getKnowledgeId(), req.getDocsName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<n-upload
:custom-request="handleImport"
directory-dnd
accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.pdf"
accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,.pdf,.txt,.md"
>
<n-upload-dragger>
<div style="margin-bottom: 12px">
Expand Down

0 comments on commit 03cb500

Please sign in to comment.