Skip to content

Commit

Permalink
Merge pull request #723 from hwchase17/nc/pinecone-remove-nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos authored Apr 11, 2023
2 parents 02ddfc2 + 572a6a4 commit 195321f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions langchain/src/vectorstores/pinecone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ export class PineconeStore extends VectorStore {
ids?: string[]
): Promise<void> {
const documentIds = ids == null ? documents.map(() => uuidv4()) : ids;
const pineconeVectors = vectors.map((values, idx) => ({
id: documentIds[idx],
metadata: flatten({
const pineconeVectors = vectors.map((values, idx) => {
// Pinecone doesn't support nested objects, so we flatten them
const metadata: {
[key: string]: string | number | boolean | null;
} = flatten({
...documents[idx].metadata,
[this.textKey]: documents[idx].pageContent,
}) as object,
values,
}));
});
// Pinecone doesn't support null values, so we remove them
for (const key of Object.keys(metadata)) {
if (metadata[key] == null) {
delete metadata[key];
}
}
return {
id: documentIds[idx],
metadata,
values,
};
});

// Pinecone recommends a limit of 100 vectors per upsert request
const chunkSize = 50;
Expand Down

0 comments on commit 195321f

Please sign in to comment.