mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 13:01:14 +03:00
fix mongodb vector database where no documents are returned
This commit is contained in:
@@ -50,7 +50,7 @@ class ElasicsearchUpsert_VectorStores extends ElasticSearchBase implements INode
|
|||||||
delete d.metadata.loc
|
delete d.metadata.loc
|
||||||
})
|
})
|
||||||
// end of workaround
|
// end of workaround
|
||||||
return super.init(nodeData, _, options, flattenDocs)
|
return super.init(nodeData, _, options, finalDocs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { ICommonObject, INode, INodeData } from '../../../src/Interface'
|
import { Collection } from 'mongodb'
|
||||||
|
import { MongoDBAtlasVectorSearch } from 'langchain/vectorstores/mongodb_atlas'
|
||||||
import { Embeddings } from 'langchain/embeddings/base'
|
import { Embeddings } from 'langchain/embeddings/base'
|
||||||
import { VectorStore } from 'langchain/vectorstores/base'
|
import { VectorStore } from 'langchain/vectorstores/base'
|
||||||
import { Document } from 'langchain/document'
|
import { Document } from 'langchain/document'
|
||||||
|
|
||||||
import { MongoDBSearchBase } from './MongoDBSearchBase'
|
import { MongoDBSearchBase } from './MongoDBSearchBase'
|
||||||
import { Collection } from 'mongodb'
|
import { ICommonObject, INode, INodeData } from '../../../src/Interface'
|
||||||
import { MongoDBAtlasVectorSearch } from 'langchain/vectorstores/mongodb_atlas'
|
|
||||||
|
|
||||||
class MongoDBExisting_VectorStores extends MongoDBSearchBase implements INode {
|
class MongoDBExisting_VectorStores extends MongoDBSearchBase implements INode {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -20,7 +19,7 @@ class MongoDBExisting_VectorStores extends MongoDBSearchBase implements INode {
|
|||||||
return super.init(nodeData, _, options, undefined)
|
return super.init(nodeData, _, options, undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
constructVectorStore(
|
async constructVectorStore(
|
||||||
embeddings: Embeddings,
|
embeddings: Embeddings,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
indexName: string,
|
indexName: string,
|
||||||
@@ -28,13 +27,12 @@ class MongoDBExisting_VectorStores extends MongoDBSearchBase implements INode {
|
|||||||
embeddingKey: string,
|
embeddingKey: string,
|
||||||
_: Document<Record<string, any>>[] | undefined
|
_: Document<Record<string, any>>[] | undefined
|
||||||
): Promise<VectorStore> {
|
): Promise<VectorStore> {
|
||||||
const mongoDBAtlasVectorSearch = new MongoDBAtlasVectorSearch(embeddings, {
|
return new MongoDBAtlasVectorSearch(embeddings, {
|
||||||
collection: collection,
|
collection: collection,
|
||||||
indexName: indexName,
|
indexName: indexName,
|
||||||
textKey: textKey,
|
textKey: textKey,
|
||||||
embeddingKey: embeddingKey
|
embeddingKey: embeddingKey
|
||||||
})
|
})
|
||||||
return Promise.resolve(mongoDBAtlasVectorSearch)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { ICommonObject, INode, INodeData } from '../../../src/Interface'
|
import { flatten } from 'lodash'
|
||||||
|
import { Collection } from 'mongodb'
|
||||||
import { Embeddings } from 'langchain/embeddings/base'
|
import { Embeddings } from 'langchain/embeddings/base'
|
||||||
import { Document } from 'langchain/document'
|
import { Document } from 'langchain/document'
|
||||||
|
|
||||||
import { flatten } from 'lodash'
|
|
||||||
import { VectorStore } from 'langchain/vectorstores/base'
|
import { VectorStore } from 'langchain/vectorstores/base'
|
||||||
import { MongoDBSearchBase } from './MongoDBSearchBase'
|
|
||||||
import { Collection } from 'mongodb'
|
|
||||||
import { MongoDBAtlasVectorSearch } from 'langchain/vectorstores/mongodb_atlas'
|
import { MongoDBAtlasVectorSearch } from 'langchain/vectorstores/mongodb_atlas'
|
||||||
|
import { ICommonObject, INode, INodeData } from '../../../src/Interface'
|
||||||
|
import { MongoDBSearchBase } from './MongoDBSearchBase'
|
||||||
|
|
||||||
class MongoDBUpsert_VectorStores extends MongoDBSearchBase implements INode {
|
class MongoDBUpsert_VectorStores extends MongoDBSearchBase implements INode {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -23,7 +22,7 @@ class MongoDBUpsert_VectorStores extends MongoDBSearchBase implements INode {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
constructVectorStore(
|
async constructVectorStore(
|
||||||
embeddings: Embeddings,
|
embeddings: Embeddings,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
indexName: string,
|
indexName: string,
|
||||||
@@ -31,12 +30,14 @@ class MongoDBUpsert_VectorStores extends MongoDBSearchBase implements INode {
|
|||||||
embeddingKey: string,
|
embeddingKey: string,
|
||||||
docs: Document<Record<string, any>>[]
|
docs: Document<Record<string, any>>[]
|
||||||
): Promise<VectorStore> {
|
): Promise<VectorStore> {
|
||||||
return MongoDBAtlasVectorSearch.fromDocuments(docs, embeddings, {
|
const mongoDBAtlasVectorSearch = new MongoDBAtlasVectorSearch(embeddings, {
|
||||||
collection: collection,
|
collection: collection,
|
||||||
indexName: indexName,
|
indexName: indexName,
|
||||||
textKey: textKey,
|
textKey: textKey,
|
||||||
embeddingKey: embeddingKey
|
embeddingKey: embeddingKey
|
||||||
})
|
})
|
||||||
|
await mongoDBAtlasVectorSearch.addDocuments(docs)
|
||||||
|
return mongoDBAtlasVectorSearch
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
@@ -51,7 +52,7 @@ class MongoDBUpsert_VectorStores extends MongoDBSearchBase implements INode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.init(nodeData, _, options, flattenDocs)
|
return super.init(nodeData, _, options, finalDocs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class RedisUpsert_VectorStores extends RedisSearchBase implements INode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.init(nodeData, _, options, flattenDocs)
|
return super.init(nodeData, _, options, finalDocs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user