-
Notifications
You must be signed in to change notification settings - Fork 6
MLE-26966 Now supports NUA for processing #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| version=3.0-SNAPSHOT | ||
| version=3.1-SNAPSHOT | ||
| sparkVersion=4.1.1 | ||
| tikaVersion=3.2.3 | ||
| semaphoreVersion=5.10.0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,12 @@ | ||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||
| * Copyright (c) 2023-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||
| package com.marklogic.spark.core; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import com.marklogic.langchain4j.Langchain4jFactory; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.ConnectorException; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.Context; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.Options; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.Util; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.classifier.TextClassifier; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.classifier.TextClassifierFactory; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.embedding.ChunkSelector; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -15,19 +15,24 @@ | |||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.embedding.EmbeddingProducerFactory; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.extraction.TextExtractor; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.extraction.TikaTextExtractor; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.nuclia.NucliaClient; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.splitter.TextSplitter; | ||||||||||||||||||||||||||||||||||||
| import com.marklogic.spark.core.splitter.TextSplitterFactory; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import java.lang.reflect.InvocationTargetException; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public abstract class DocumentPipelineFactory { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static final String FACTORY_CLASS_NAME = "com.marklogic.langchain4j.Langchain4jFactory"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // For some reason, Sonar thinks the check for four nulls always resolves to false, even though it's definitely | ||||||||||||||||||||||||||||||||||||
| // possible. So ignoring that warning. | ||||||||||||||||||||||||||||||||||||
| @SuppressWarnings("java:S2589") | ||||||||||||||||||||||||||||||||||||
| public static DocumentPipeline newDocumentPipeline(Context context) { | ||||||||||||||||||||||||||||||||||||
| // Check for Nuclia configuration first | ||||||||||||||||||||||||||||||||||||
| NucliaClient nucliaClient = newNucliaClient(context); | ||||||||||||||||||||||||||||||||||||
| if (nucliaClient != null) { | ||||||||||||||||||||||||||||||||||||
| TextClassifier textClassifier = TextClassifierFactory.newTextClassifier(context); | ||||||||||||||||||||||||||||||||||||
| return new DocumentPipeline(nucliaClient, textClassifier); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Standard pipeline with separate components | ||||||||||||||||||||||||||||||||||||
| final TextExtractor textExtractor = context.getBooleanOption(Options.WRITE_EXTRACTED_TEXT, false) ? | ||||||||||||||||||||||||||||||||||||
| new TikaTextExtractor() : null; | ||||||||||||||||||||||||||||||||||||
| final TextSplitter textSplitter = newTextSplitter(context); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -52,6 +57,25 @@ public static DocumentPipeline newDocumentPipeline(Context context) { | |||||||||||||||||||||||||||||||||||
| new DocumentPipeline(textExtractor, textSplitter, textClassifier, embeddingProducer, chunkSelector); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static NucliaClient newNucliaClient(Context context) { | ||||||||||||||||||||||||||||||||||||
| String apiKey = context.getProperties().get(Options.WRITE_NUCLIA_API_KEY); | ||||||||||||||||||||||||||||||||||||
| if (apiKey == null || apiKey.trim().isEmpty()) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| final String region = context.getProperties().get(Options.WRITE_NUCLIA_REGION); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (region == null || region.trim().isEmpty()) { | ||||||||||||||||||||||||||||||||||||
| throw new ConnectorException(String.format("When %s is specified, %s must also be specified.", | ||||||||||||||||||||||||||||||||||||
| context.getOptionNameForMessage(Options.WRITE_NUCLIA_API_KEY), | ||||||||||||||||||||||||||||||||||||
| context.getOptionNameForMessage(Options.WRITE_NUCLIA_REGION))); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| int timeout = context.getIntOption(Options.WRITE_NUCLIA_TIMEOUT, 120, 1); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return new NucliaClient(apiKey, region, timeout); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static TextSplitter newTextSplitter(Context context) { | ||||||||||||||||||||||||||||||||||||
| boolean shouldSplit = context.getProperties().keySet().stream().anyMatch(key -> key.startsWith(Options.WRITE_SPLITTER_PREFIX)); | ||||||||||||||||||||||||||||||||||||
| if (!shouldSplit) { | ||||||||||||||||||||||||||||||||||||
|
|
@@ -73,24 +97,7 @@ private static EmbeddingProducer newEmbeddingProducer(Context context) { | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| /** | |
| * Creates a new Langchain4jFactory instance. | |
| * <p> | |
| * Earlier versions of this method wrapped factory construction in additional | |
| * error handling and logging. That logic was removed once Langchain4jFactory | |
| * construction became side-effect free and stopped performing configuration | |
| * work that could fail at instantiation time. Any errors related to | |
| * misconfiguration or downstream processing are now expected to surface when | |
| * the factory is actually used (for example, when creating a TextSplitter or | |
| * EmbeddingProducer), where more contextual information is available. | |
| * <p> | |
| * As a result, direct instantiation here is considered safe and avoids | |
| * redundant, low-value exception handling that would only rethrow generic | |
| * runtime failures. | |
| */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The okhttp-sse dependency version (5.2.1) differs from the okhttp version (5.2.0) specified earlier in the file. Consider aligning these versions to avoid potential compatibility issues.