Skip to content

Commit

Permalink
polish : use lamda for document enricher
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed May 27, 2024
1 parent ed780c4 commit 8eb656d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
14 changes: 7 additions & 7 deletions rag/rag-springai-ollama-llm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -127,9 +127,9 @@
<palantirJavaFormat>
<version>2.47.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
<formatAnnotations />
<importOrder/>
<removeUnusedImports/>
<formatAnnotations/>
</java>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.learning.ai.llmragwithspringai.service;

import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.prompt.transformer.TransformerContentType;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentReader;
import org.springframework.ai.document.DocumentTransformer;
import org.springframework.ai.reader.ExtractedTextFormatter;
Expand Down Expand Up @@ -53,15 +51,12 @@ public void loadData(Resource documentResource) {
}
if (documentReader != null) {
LOGGER.info("Loading text document to redis vector database");
var metadataEnricher = new DocumentTransformer() {
@Override
public List<Document> apply(List<Document> documents) {
documents.forEach(d -> {
Map<String, Object> metadata = d.getMetadata();
metadata.put(TransformerContentType.EXTERNAL_KNOWLEDGE, "true");
});
return documents;
}
DocumentTransformer metadataEnricher = documents -> {
documents.forEach(d -> {
Map<String, Object> metadata = d.getMetadata();
metadata.put(TransformerContentType.EXTERNAL_KNOWLEDGE, "true");
});
return documents;
};
vectorStore.accept(metadataEnricher.apply(tokenTextSplitter.apply(documentReader.get())));
LOGGER.info("Loaded document to redis vector database.");
Expand Down
8 changes: 4 additions & 4 deletions rag/rag-springai-openai-llm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@
<configuration>
<java>
<palantirJavaFormat>
<version>2.40.0</version>
<version>2.47.0</version>
</palantirJavaFormat>
<importOrder />
<removeUnusedImports />
<formatAnnotations />
<importOrder/>
<removeUnusedImports/>
<formatAnnotations/>
</java>
</configuration>
<executions>
Expand Down

0 comments on commit 8eb656d

Please sign in to comment.