Skip to content
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

small code improvements/clean-ups #2077

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.ai.vectorstore;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -100,22 +99,10 @@ public SimpleVectorStoreContent(String id, String text, Map<String, Object> meta

this.id = id;
this.text = text;
this.metadata = Collections.unmodifiableMap(new HashMap<>(metadata));
this.metadata = Map.copyOf(metadata);
this.embedding = Arrays.copyOf(embedding, embedding.length);
}

/**
* Creates a new instance with an updated embedding vector.
* @param embedding the new embedding vector, must not be null
* @return a new instance with the updated embedding
* @throws IllegalArgumentException if embedding is null or empty
*/
public SimpleVectorStoreContent withEmbedding(float[] embedding) {
Assert.notNull(embedding, "embedding must not be null");
Assert.isTrue(embedding.length > 0, "embedding vector must not be empty");
return new SimpleVectorStoreContent(this.id, this.text, this.metadata, embedding);
}

public String getId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
* }</pre>
*
*
* This builder DSL mimics the common https://www.baeldung.com/hibernate-criteria-queries
* This builder DSL mimics the common
* <a href="https://www.baeldung.com/hibernate-criteria-queries">Criteria Queries</a>
* syntax.
*
* @author Christian Tzolov
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import org.antlr.v4.runtime.ANTLRErrorStrategy;
import org.antlr.v4.runtime.BailErrorStrategy;
Expand All @@ -46,7 +45,7 @@
*
* The vector-store agnostic, filter expression language is defined by a formal ANTLR4
* grammar (Filters.g4). The language looks and feels like a subset of the well known SQL
* WHERE filter expressions. For example you can use the parser like this:
* WHERE filter expressions. For example, you can use the parser like this:
*
* <pre>{@code
*
Expand Down Expand Up @@ -151,7 +150,7 @@ public Filter.Expression parse(String textFilterExpression) {
return filterExpression;
}
catch (ParseCancellationException e) {
var msg = this.errorListener.errorMessages.stream().collect(Collectors.joining());
var msg = String.join("", this.errorListener.errorMessages);
var rootCause = NestedExceptionUtils.getRootCause(e);
throw new FilterExpressionParseException(msg, rootCause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* Converts {@link Expression} into Pinecone metadata filter expression format.
* (https://docs.pinecone.io/docs/metadata-filtering)
* (<a href="https://docs.pinecone.io/docs/metadata-filtering">Metadata filtering</a>)
*
* @author Christian Tzolov
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ private String getOperationSymbol(Expression exp) {
@Override
protected void doKey(Key key, StringBuilder context) {
var identifier = (hasOuterQuotes(key.key())) ? removeOuterQuotes(key.key()) : key.key();
context.append("\"" + identifier + "\": ");
context.append("\"").append(identifier).append("\": ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PrintFilterExpressionConverter extends AbstractFilterExpressionConv

public void doExpression(Expression expression, StringBuilder context) {
this.convertOperand(expression.left(), context);
context.append(" " + expression.type() + " ");
context.append(" ").append(expression.type()).append(" ");
this.convertOperand(expression.right(), context);

}
Expand Down