Skip to content
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
6 changes: 4 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
WEAVIATE_135: 1.35.16
WEAVIATE_136: 1.36.10
WEAVIATE_137: 1.37.5
WEAVIATE_138: 1.38.2

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -44,8 +45,9 @@ jobs:
{ node: "24.x", weaviate: $WEAVIATE_134 },
{ node: "24.x", weaviate: $WEAVIATE_135 },
{ node: "24.x", weaviate: $WEAVIATE_136 },
{ node: "22.x", weaviate: $WEAVIATE_137 },
{ node: "24.x", weaviate: $WEAVIATE_137 },
{ node: "22.x", weaviate: $WEAVIATE_138 },
{ node: "24.x", weaviate: $WEAVIATE_138 },
]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand Down Expand Up @@ -75,7 +77,7 @@ jobs:
strategy:
fail-fast: false
matrix:
versions: [{ node: "24.x", weaviate: $WEAVIATE_137 }]
versions: [{ node: "24.x", weaviate: $WEAVIATE_138 }]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3
Expand Down
2 changes: 2 additions & 0 deletions src/collections/config/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export type ReplicationDeletionStrategy =
export type AsyncReplicationConfig = WeaviateAsyncReplicationConfig;

export type ReplicationConfig = {
/** @deprecated From v1.38 onwards this setting is determined server-side
* and should be considered read-only.*/
asyncEnabled: boolean;
asyncConfig?: AsyncReplicationConfig;
deletionStrategy: ReplicationDeletionStrategy;
Expand Down
4 changes: 3 additions & 1 deletion src/collections/query/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterValue } from '../filters/index.js';
import { CallOptions, MultiTargetVectorJoin, ReturnVectors } from '../index.js';
import { BoostOptions, CallOptions, MultiTargetVectorJoin, ReturnVectors } from '../index.js';
import { Sorting } from '../sort/classes.js';
import {
GroupByOptions,
Expand Down Expand Up @@ -61,6 +61,8 @@ export type SearchOptions<T, I> = {
autoLimit?: number;
/** The filters to be applied to the query. Use `weaviate.filter.*` to create filters */
filters?: FilterValue;
/** Promote search results based on a boosting function. */
boost?: BoostOptions;
/** How to rerank the query results. Requires a configured [reranking](https://weaviate.io/developers/weaviate/concepts/reranking) module. */
rerank?: RerankOptions<T>;
/** Whether to include the vector of the object in the response. If using named vectors, pass an array of strings to include only specific vectors. */
Expand Down
98 changes: 97 additions & 1 deletion src/collections/query/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { MultiTargetVectorJoin, Vectors } from '../index.js';
import { WeaviateInvalidInputError } from '../../errors.js';
import {
BoostOptions,
FilterValue,
MultiTargetVectorJoin,
NumericDecay,
PropertyValue,
TimeDecay,
Vectors,
} from '../index.js';
import {
Bm25OperatorOptions,
Bm25OperatorOr,
Expand Down Expand Up @@ -67,6 +76,93 @@ export class TargetVectorInputGuards {
}
}

export class Boost {
static filter(filter: FilterValue, args?: Pick<BoostOptions, 'weight' | 'depth'>): BoostOptions {
return {
...args,
conditions: [
{
weight: args?.weight,
func: {
...filter,
type: 'filter',
},
},
],
};
}
static timeDecay(args: Omit<TimeDecay, 'type'> & Pick<BoostOptions, 'weight' | 'depth'>): BoostOptions {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'timeDecay',
},
},
],
weight,
depth,
};
}
static numericDecay(
args: Omit<NumericDecay, 'type'> & Pick<BoostOptions, 'weight' | 'depth'>
): BoostOptions {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'numericDecay',
},
},
],
weight,
depth,
};
}
static numericProperty(
args: Omit<PropertyValue, 'type'> & Pick<BoostOptions, 'weight' | 'depth'>
): BoostOptions {
const { weight, depth, ...func } = args;
return {
conditions: [
{
weight,
func: {
...func,
type: 'propertyValue',
},
},
],
weight,
depth,
};
}
static blend(boosts: BoostOptions[], options: Pick<BoostOptions, 'weight' | 'depth'>): BoostOptions {
const out: BoostOptions = { ...options, conditions: [] };
for (const boost of boosts) {
if (boost.depth) {
throw new WeaviateInvalidInputError('A boost passed to Boost.blend() cannot set its own depth.');
}
for (let cond of boost.conditions) {
if (!cond.weight && boost.weight) {
cond = {
...cond,
weight: boost.weight,
};
}
out.conditions.push({ ...cond });
}
}
return out;
}
}

export class Bm25Operator {
static and(): Bm25OperatorOptions {
return { operator: 'And' };
Expand Down
92 changes: 92 additions & 0 deletions src/collections/serialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ import {
GenerativeSearch_Single,
} from '../../proto/v1/generative.js';
import {
Boost as BoostGRPC,
Boost_Condition,
Boost_DecayCurve,
Boost_NumericDecayFunction,
Boost_PropertyValueFunction,
Boost_PropertyValueModifier,
Boost_TimeDecayFunction,
GroupBy,
MetadataRequest,
ObjectPropertiesRequest,
Expand Down Expand Up @@ -111,13 +118,19 @@ import {
AggregateHybridOptions,
AggregateNearOptions,
BatchReference,
BoostOptions,
Curve,
GenerativeConfigRuntime,
GroupByAggregate,
GroupedTask,
Modifier,
MultiTargetVectorJoin,
NumericDecay,
PrimitiveKeys,
PropertiesMetrics,
PropertyValue,
SinglePrompt,
TimeDecay,
} from '../index.js';
import {
BaseHybridOptions,
Expand Down Expand Up @@ -649,6 +662,7 @@ class Search {
limit: args?.limit,
offset: args?.offset,
filters: args?.filters ? Serialize.filtersGRPC(args.filters) : undefined,
boost: args?.boost ? Serialize.boostGRPC(args.boost) : undefined,
properties:
args?.returnProperties || args?.returnReferences
? Search.queryProperties(args.returnProperties, args.returnReferences)
Expand Down Expand Up @@ -1544,6 +1558,84 @@ export class Serialize {
});
};

private static boostCurve(curve?: Curve): Boost_DecayCurve {
switch (curve) {
case 'exponential':
return Boost_DecayCurve.DECAY_CURVE_EXPONENTIAL;
case 'gaussian':
return Boost_DecayCurve.DECAY_CURVE_GAUSS;
case 'linear':
return Boost_DecayCurve.DECAY_CURVE_LINEAR;
default:
return Boost_DecayCurve.DECAY_CURVE_UNSPECIFIED;
}
}

private static boostModifier(modifier?: Modifier): Boost_PropertyValueModifier {
switch (modifier) {
case 'log1p':
return Boost_PropertyValueModifier.PROPERTY_VALUE_MODIFIER_LOG1P;
case 'sqrt':
return Boost_PropertyValueModifier.PROPERTY_VALUE_MODIFIER_LOG1P;
default:
return Boost_PropertyValueModifier.PROPERTY_VALUE_MODIFIER_UNSPECIFIED;
}
}

public static boostGRPC = (boost: BoostOptions): BoostGRPC => {
const out: BoostGRPC = { weight: boost.weight, depth: boost.depth, conditions: [] };
for (const cond of boost.conditions) {
let condProto: Boost_Condition = { weight: cond.weight };
const { type, ...func } = cond.func;

switch (type) {
case 'filter':
condProto = {
...condProto,
filter: this.filtersGRPC(func as FilterValue),
};
break;
case 'timeDecay': {
const { curve, ...timeDecay } = func as TimeDecay;
condProto = {
...condProto,
timeDecay: Boost_TimeDecayFunction.fromPartial({
...timeDecay,
curve: this.boostCurve(curve),
}),
};
break;
}
case 'numericDecay': {
const { curve, ...numericDecay } = func as NumericDecay;
condProto = {
...condProto,
numericDecay: Boost_NumericDecayFunction.fromPartial({
...numericDecay,
curve: this.boostCurve(curve),
}),
};
break;
}
case 'propertyValue': {
const { modifier, ...propertyValue } = func as PropertyValue;
condProto = {
...condProto,
propertyValue: Boost_PropertyValueFunction.fromPartial({
...propertyValue,
modifier: this.boostModifier(modifier),
}),
};
break;
}
}
out.conditions.push(condProto);
}

console.error(JSON.stringify(out));
return out;
};

public static filtersGRPC = (filters: FilterValue): FiltersGRPC => {
const resolveFilters = (filters: FilterValue): FiltersGRPC[] => {
const out: FiltersGRPC[] = [];
Expand Down
40 changes: 39 additions & 1 deletion src/collections/types/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WeaviateField } from '../index.js';
import { FilterValue, WeaviateField } from '../index.js';
import { PrimitiveVectorType } from '../query/types.js';
import { CrossReferenceDefault } from '../references/index.js';
import {
Expand Down Expand Up @@ -189,3 +189,41 @@ export type SortBy = {
property: string;
ascending?: boolean;
};

export type BoostOptions = {
conditions: {
func: TimeDecay | NumericDecay | PropertyValue | (FilterValue & { type: 'filter' });
weight?: number;
}[];
weight?: number;
depth?: number;
};

export type Curve = 'exponential' | 'gaussian' | 'linear';
export type Modifier = 'log1p' | 'sqrt';

export type TimeDecay = {
property: string;
scale: string;
origin?: string;
offset?: string;
curve?: Curve;
decay?: number;
type: 'timeDecay';
};

export type NumericDecay = {
property: string;
scale: number;
origin: number;
offset?: number;
curve?: Curve;
decay?: number;
type: 'numericDecay';
};

export type PropertyValue = {
property: string;
modifier?: Modifier;
type: 'propertyValue';
};
2 changes: 2 additions & 0 deletions src/grpc/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
NearVideoSearch,
} from '../proto/v1/base_search.js';
import {
Boost,
GroupBy,
MetadataRequest,
PropertiesRequest,
Expand Down Expand Up @@ -50,6 +51,7 @@ export type BaseSearchArgs = {
offset?: number;
autocut?: number;
filters?: Filters;
boost?: Boost;
rerank?: Rerank;
metadata?: MetadataRequest;
properties?: PropertiesRequest;
Expand Down
Loading
Loading