Skip to content

Commit 4408f90

Browse files
committed
Implemented DenseVectorEmbedding plan analysis.
1 parent bf905ee commit 4408f90

File tree

1 file changed

+34
-0
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis

1 file changed

+34
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import org.elasticsearch.xpack.esql.plan.logical.inference.Completion;
9898
import org.elasticsearch.xpack.esql.plan.logical.inference.InferencePlan;
9999
import org.elasticsearch.xpack.esql.plan.logical.inference.Rerank;
100+
import org.elasticsearch.xpack.esql.plan.logical.inference.embedding.DenseVectorEmbedding;
100101
import org.elasticsearch.xpack.esql.plan.logical.join.Join;
101102
import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig;
102103
import org.elasticsearch.xpack.esql.plan.logical.join.JoinType;
@@ -138,6 +139,7 @@
138139
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
139140
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
140141
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_PERIOD;
142+
import static org.elasticsearch.xpack.esql.core.type.DataType.DENSE_VECTOR;
141143
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
142144
import static org.elasticsearch.xpack.esql.core.type.DataType.FLOAT;
143145
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
@@ -516,6 +518,10 @@ protected LogicalPlan rule(LogicalPlan plan, AnalyzerContext context) {
516518
return resolveEval(p, childrenOutput);
517519
}
518520

521+
if (plan instanceof DenseVectorEmbedding dve) {
522+
return resolveDenseVectorEmbedding(dve, childrenOutput);
523+
}
524+
519525
if (plan instanceof Enrich p) {
520526
return resolveEnrich(p, childrenOutput);
521527
}
@@ -820,6 +826,34 @@ private LogicalPlan resolveFork(Fork fork, AnalyzerContext context) {
820826
return changed ? new Fork(fork.source(), newSubPlans, newOutput) : fork;
821827
}
822828

829+
private LogicalPlan resolveDenseVectorEmbedding(DenseVectorEmbedding p, List<Attribute> childrenOutput) {
830+
// Resolve the input expression
831+
Expression input = p.input();
832+
if (input.resolved() == false) {
833+
input = input.transformUp(UnresolvedAttribute.class, ua -> maybeResolveAttribute(ua, childrenOutput));
834+
}
835+
836+
// Resolve the target field (similar to Completion)
837+
Attribute targetField = p.embeddingField();
838+
if (targetField instanceof UnresolvedAttribute ua) {
839+
targetField = new ReferenceAttribute(ua.source(), ua.name(), DENSE_VECTOR);
840+
}
841+
842+
// Create a new DenseVectorEmbedding with resolved expressions
843+
// Only create a new instance if something changed to avoid unnecessary object creation
844+
if (input != p.input() || targetField != p.embeddingField()) {
845+
return new DenseVectorEmbedding(
846+
p.source(),
847+
p.child(),
848+
p.inferenceId(),
849+
input,
850+
targetField
851+
);
852+
}
853+
854+
return p;
855+
}
856+
823857
private LogicalPlan resolveRerank(Rerank rerank, List<Attribute> childrenOutput) {
824858
List<Alias> newFields = new ArrayList<>();
825859
boolean changed = false;

0 commit comments

Comments
 (0)