Skip to content

Commit

Permalink
so there are still test failures. let's check tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
christophstrobl committed Jan 29, 2025
1 parent b74f1d7 commit 4ac2283
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ default LimitContributor vector(float... vector) {
return vector(Vector.of(vector));
}

/**
* Array of byte numbers that represent the query vector. The number type must match the indexed field value type.
* Otherwise, Atlas Vector Search doesn't return any results or errors.
*
* @param vector the query vector.
* @return
*/
@Contract("_ -> this")
default LimitContributor vector(byte... vector) {
return vector(BinaryVector.int8Vector(vector));
}

/**
* Array of double numbers that represent the query vector. The number type must match the indexed field value type.
* Otherwise, Atlas Vector Search doesn't return any results or errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.data.mongodb.core.convert;

import static org.springframework.data.convert.ConverterBuilder.*;
import static org.springframework.data.convert.ConverterBuilder.reading;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -27,6 +27,7 @@
import java.util.Collection;
import java.util.Currency;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
Expand All @@ -47,10 +48,10 @@
import org.bson.types.Code;
import org.bson.types.Decimal128;
import org.bson.types.ObjectId;

import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalConverter;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.data.convert.ReadingConverter;
Expand All @@ -60,6 +61,7 @@
import org.springframework.data.mongodb.core.mapping.MongoVector;
import org.springframework.data.mongodb.core.query.Term;
import org.springframework.data.mongodb.core.script.NamedMongoScript;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -473,6 +475,36 @@ public Vector convert(BinaryVector source) {
}
}

// @WritingConverter
// enum BytesToBinaryVectorConverter implements ConditionalGenericConverter {
// INSTANCE;
//
// @Nullable
// public BinaryVector convert(byte[] source) {
// return BinaryVector.int8Vector(source);
// }
//
// @Override
// public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
// return sourceType.getType() == byte[].class && targetType.getType() == BinaryVector.class;
// }
//
// @Nullable
// @Override
// public Set<ConvertiblePair> getConvertibleTypes() {
// return Set.of(new ConvertiblePair(byte[].class, BinaryVector.class));
// }
//
// @Nullable
// @Override
// public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
// if(!matches(sourceType, targetType)) {
// return source;
// }
// return convert((byte[]) source);
// }
// }

/**
* {@link ConverterFactory} implementation converting {@link AtomicLong} into {@link Long}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ public interface SearchIndexOperations {
void updateIndex(SearchIndexDefinition index);

/**
* Check whether an index with the {@code name} exists.
* Check whether an index with the {@code name} exists. To ensure an existing index is queryable it is recommended to
* check its {@link #status(String) status}.
*
* @param name name of index to check for presence.
* @return {@literal true} if the index exists; {@literal false} otherwise.
*/
boolean exists(String name);


/**
* Check the actual {@link SearchIndexStatus} of an index.
*
* @param name name of index to check for presence.
* @return {@literal true} if the index exists; {@literal false} otherwise.
*/
SearchIndexStatus status(String name);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,8 +16,10 @@
package org.springframework.data.mongodb.core.index;

/**
* Representation of different conditions a search index can be in.
*
* @author Christoph Strobl
* @since 2025/01
* @since 4.5
*/
public enum SearchIndexStatus {

Expand All @@ -30,7 +32,7 @@ public enum SearchIndexStatus {
/** will cease to exist - no longer queryable */
DELETING,

/** well, that did not work - not queryable */
/** well, this one is broken - not queryable */
FAILED,

/** busy with other things, check back later - not queryable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Date;
import java.util.regex.Pattern;

import org.bson.BinaryVector;
import org.bson.BsonBinary;
import org.bson.types.BSONTimestamp;
import org.bson.types.Binary;
import org.bson.types.Code;
Expand Down Expand Up @@ -55,7 +57,8 @@ public enum FieldType {
INT32(15, Integer.class), //
TIMESTAMP(16, BSONTimestamp.class), //
INT64(17, Long.class), //
DECIMAL128(18, Decimal128.class);
DECIMAL128(18, Decimal128.class),
VECTOR(5, BinaryVector.class);

private final int bsonType;
private final Class<?> javaClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,19 @@ public static Object toJavaType(BsonValue value) {
case BOOLEAN -> value.asBoolean().getValue();
case OBJECT_ID -> value.asObjectId().getValue();
case DB_POINTER -> new DBRef(value.asDBPointer().getNamespace(), value.asDBPointer().getId());
case BINARY -> value.asBinary().getData();
case BINARY -> {

BsonBinary binary = value.asBinary();
if(binary.getType() != BsonBinarySubType.VECTOR.getValue()) {
yield binary.getData();
}
yield value.asBinary().asVector();
}
case DATE_TIME -> new Date(value.asDateTime().getValue());
case SYMBOL -> value.asSymbol().getSymbol();
case ARRAY -> value.asArray().toArray();
case DOCUMENT -> Document.parse(value.asDocument().toJson());

default -> value;
};
}
Expand Down
Loading

0 comments on commit 4ac2283

Please sign in to comment.