Skip to content

Commit

Permalink
community[patch]: ensure AstraDB createCollectionOptions are aligned …
Browse files Browse the repository at this point in the history
…with py version (#5185)

* community[fix]: ensure AstraDB createCollectionOptions are aligned with py version

* fix

* fix
  • Loading branch information
nicoloboschi committed Apr 24, 2024
1 parent df43448 commit 5f96f4a
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions libs/langchain-community/src/vectorstores/astradb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,34 @@ export class AstraDBVectorStore extends VectorStore {
} = args;
const dataAPIClient = new DataAPIClient(token, { caller: ["langchainjs"] });
this.astraDBClient = dataAPIClient.db(endpoint, { namespace });
this.collectionName = collection;
this.collectionOptions = collectionOptions;
if (
!this.collectionOptions ||
this.collectionOptions.checkExists === undefined
) {
this.collectionOptions = {
checkExists: false,
...(this.collectionOptions || {}),
};
this.skipCollectionProvisioning = skipCollectionProvisioning ?? false;
if (this.skipCollectionProvisioning && collectionOptions) {
throw new Error(
"If 'skipCollectionProvisioning' has been set to true, 'collectionOptions' must not be defined"
);
}
this.collectionName = collection;
this.collectionOptions =
AstraDBVectorStore.applyCollectionOptionsDefaults(collectionOptions);
this.idKey = idKey ?? "_id";
this.contentKey = contentKey ?? "text";
this.batchSize = batchSize && batchSize <= 20 ? batchSize : 20;
this.caller = new AsyncCaller(callerArgs);
this.skipCollectionProvisioning = skipCollectionProvisioning ?? false;
if (this.skipCollectionProvisioning && this.collectionOptions) {
throw new Error(
"If 'skipCollectionProvisioning' has been set to true, 'collectionOptions' must not be defined"
);
}

private static applyCollectionOptionsDefaults(
fromUser?: CreateCollectionOptions<any>
): CreateCollectionOptions<any> {
const copy: CreateCollectionOptions<any> = fromUser ? { ...fromUser } : {};
if (copy.checkExists === undefined) {
copy.checkExists = false;
}
if (copy.indexing === undefined) {
// same default as langchain python AstraDBVectorStore.
// this enables to create the collection in python/ts and use it in ts/python with default options.
copy.indexing = { allow: ["metadata"] };
}
return copy;
}

/**
Expand Down

0 comments on commit 5f96f4a

Please sign in to comment.