-
Notifications
You must be signed in to change notification settings - Fork 6
MLE-26966 Added Nuclia metadata #610
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
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 |
|---|---|---|
|
|
@@ -65,19 +65,18 @@ protected DocumentWriteOperation makeChunkDocument() { | |
| Element chunksElement = doc.createElementNS(chunkConfig.getXmlNamespace(), DEFAULT_CHUNKS_ELEMENT_NAME); | ||
| root.appendChild(chunksElement); | ||
|
|
||
| List<Chunk> chunks = new ArrayList<>(); | ||
| List<Chunk> addedChunks = new ArrayList<>(); | ||
| for (int i = 0; i < this.maxChunksPerDocument && hasNext(); i++) { | ||
| ChunkInputs chunkInputs = chunkInputsList.get(listIndex); | ||
| Element classificationResponseNode = chunkInputs.getClassification() != null ? | ||
| getClassificationResponseElement(chunkInputs.getClassification()) : null; | ||
| addChunk(doc, chunkInputs.getText(), chunksElement, chunks, classificationResponseNode, chunkInputs.getEmbedding(), chunkInputs.getModelName()); | ||
| DOMChunk chunk = addChunk(doc, chunkInputs, chunksElement); | ||
| addedChunks.add(chunk); | ||
| listIndex++; | ||
| } | ||
|
|
||
| final String chunkDocumentUri = makeChunkDocumentUri(sourceDocument, "xml"); | ||
| return new DocumentAndChunks( | ||
| new DocumentWriteOperationImpl(chunkDocumentUri, chunkConfig.getMetadata(), new DOMHandle(doc)), | ||
| chunks | ||
| addedChunks | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -87,16 +86,15 @@ protected DocumentWriteOperation addChunksToSourceDocument() { | |
| Element chunksElement = doc.createElementNS(chunkConfig.getXmlNamespace(), determineChunksElementName(doc)); | ||
| doc.getDocumentElement().appendChild(chunksElement); | ||
|
|
||
| List<Chunk> chunks = new ArrayList<>(); | ||
| List<Chunk> addedChunks = new ArrayList<>(); | ||
| for (ChunkInputs chunkInputs : chunkInputsList) { | ||
| Element classificationResponseNode = chunkInputs.getClassification() != null ? | ||
| getClassificationResponseElement(chunkInputs.getClassification()) : null; | ||
| addChunk(doc, chunkInputs.getText(), chunksElement, chunks, classificationResponseNode, chunkInputs.getEmbedding(), chunkInputs.getModelName()); | ||
| DOMChunk chunk = addChunk(doc, chunkInputs, chunksElement); | ||
| addedChunks.add(chunk); | ||
| } | ||
|
|
||
| return new DocumentAndChunks( | ||
| new DocumentWriteOperationImpl(sourceDocument.getUri(), sourceDocument.getMetadata(), new DOMHandle(doc)), | ||
| chunks | ||
| addedChunks | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -110,15 +108,16 @@ private Element getClassificationResponseElement(byte[] classificationBytes) { | |
| } | ||
| } | ||
|
|
||
| private void addChunk(Document doc, String textSegment, Element chunksElement, List<Chunk> chunks, Element classificationResponse, float[] embedding, String modelName) { | ||
| private DOMChunk addChunk(Document doc, ChunkInputs chunkInputs, Element chunksElement) { | ||
| Element chunk = doc.createElementNS(chunkConfig.getXmlNamespace(), "chunk"); | ||
| chunksElement.appendChild(chunk); | ||
|
|
||
| Element text = doc.createElementNS(chunkConfig.getXmlNamespace(), "text"); | ||
| text.setTextContent(textSegment); | ||
| text.setTextContent(chunkInputs.getText()); | ||
| chunk.appendChild(text); | ||
|
|
||
| if (classificationResponse != null) { | ||
| if (chunkInputs.getClassification() != null) { | ||
| Element classificationResponse = getClassificationResponseElement(chunkInputs.getClassification()); | ||
| Node classificationNode = doc.createElement("classification"); | ||
| chunk.appendChild(classificationNode); | ||
| for (int i = 0; i < classificationResponse.getChildNodes().getLength(); i++) { | ||
|
|
@@ -127,11 +126,21 @@ private void addChunk(Document doc, String textSegment, Element chunksElement, L | |
| } | ||
| } | ||
|
|
||
| if (chunkInputs.getMetadata() != null) { | ||
| Element metadataElement = doc.createElementNS(chunkConfig.getXmlNamespace(), "chunk-metadata"); | ||
| // Re: possibly converting JSON to XML - Copilot recommends using the serialized string, as there's no | ||
| // "correct" way for converting JSON to XML, particularly in regard to arrays. If the user wants XML | ||
| // documents, they can always e.g. use a REST transform to determine how they want to represent the JSON | ||
| // as XML. | ||
| metadataElement.setTextContent(chunkInputs.getMetadata().toString()); | ||
|
||
| chunk.appendChild(metadataElement); | ||
| } | ||
|
|
||
| var domChunk = new DOMChunk(doc, chunk, this.xmlChunkConfig, this.xPathFactory); | ||
| if (embedding != null) { | ||
| domChunk.addEmbedding(embedding, modelName); | ||
| if (chunkInputs.getEmbedding() != null) { | ||
| domChunk.addEmbedding(chunkInputs.getEmbedding(), chunkInputs.getModelName()); | ||
| } | ||
| chunks.add(domChunk); | ||
| return domChunk; | ||
| } | ||
|
|
||
| private String determineChunksElementName(Document doc) { | ||
|
|
||
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
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 metadata is set unconditionally outside the null check that applies to embedding and modelName. This inconsistency could be confusing. Consider moving this line inside the if block or adding a comment explaining why metadata is handled differently.