Skip to content

Commit

Permalink
allow to modify OpenSerach number of shards/replicas (#4372)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-anis-snoussi authored Feb 12, 2024
1 parent 8d193ed commit f78f4f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libs/langchain-community/src/vectorstores/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface VectorSearchOptions {
readonly m?: number;
readonly efConstruction?: number;
readonly efSearch?: number;
readonly numberOfShards?: number;
readonly numberOfReplicas?: number;
}

/**
Expand Down Expand Up @@ -83,6 +85,10 @@ export class OpenSearchVectorStore extends VectorStore {

private readonly efSearch: number;

private readonly numberOfShards: number;

private readonly numberOfReplicas: number;

private readonly m: number;

_vectorstoreType(): string {
Expand All @@ -97,6 +103,8 @@ export class OpenSearchVectorStore extends VectorStore {
this.m = args.vectorSearchOptions?.m ?? 16;
this.efConstruction = args.vectorSearchOptions?.efConstruction ?? 512;
this.efSearch = args.vectorSearchOptions?.efSearch ?? 512;
this.numberOfShards = args.vectorSearchOptions?.numberOfShards ?? 5;
this.numberOfReplicas = args.vectorSearchOptions?.numberOfReplicas ?? 1;

this.client = args.client;
this.indexName = args.indexName ?? "documents";
Expand Down Expand Up @@ -137,6 +145,8 @@ export class OpenSearchVectorStore extends VectorStore {
this.spaceType,
this.efSearch,
this.efConstruction,
this.numberOfShards,
this.numberOfReplicas,
this.m
);
const documentIds =
Expand Down Expand Up @@ -279,13 +289,15 @@ export class OpenSearchVectorStore extends VectorStore {
spaceType = "l2",
efSearch = 512,
efConstruction = 512,
numberOfShards = 5,
numberOfReplicas = 1,
m = 16
): Promise<void> {
const body = {
settings: {
index: {
number_of_shards: 5,
number_of_replicas: 1,
number_of_shards: numberOfShards,
number_of_replicas: numberOfReplicas,
knn: true,
"knn.algo_param.ef_search": efSearch,
},
Expand Down

0 comments on commit f78f4f4

Please sign in to comment.