MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / queryVectorStore

Function queryVectorStore

packages/server/src/services/documentstore/index.ts:1489–1576  ·  view source on GitHub ↗
(data: ICommonObject)

Source from the content-addressed store, hash-verified

1487}
1488
1489const queryVectorStore = async (data: ICommonObject) => {
1490 try {
1491 const appServer = getRunningExpressApp()
1492 const componentNodes = appServer.nodesPool.componentNodes
1493
1494 const entity = await appServer.AppDataSource.getRepository(DocumentStore).findOneBy({
1495 id: data.storeId
1496 })
1497 if (!entity) {
1498 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Document store ${data.storeId} not found`)
1499 }
1500 const options: ICommonObject = {
1501 chatflowid: uuidv4(),
1502 appDataSource: appServer.AppDataSource,
1503 databaseEntities,
1504 logger
1505 }
1506
1507 if (!entity.embeddingConfig) {
1508 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Embedding for ${data.storeId} is not configured`)
1509 }
1510
1511 if (!entity.vectorStoreConfig) {
1512 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Vector Store for ${data.storeId} is not configured`)
1513 }
1514
1515 const embeddingConfig = JSON.parse(entity.embeddingConfig)
1516 data.embeddingName = embeddingConfig.name
1517 data.embeddingConfig = embeddingConfig.config
1518 let embeddingObj = await _createEmbeddingsObject(componentNodes, data, options)
1519
1520 const vsConfig = JSON.parse(entity.vectorStoreConfig)
1521 data.vectorStoreName = vsConfig.name
1522 data.vectorStoreConfig = vsConfig.config
1523 if (data.inputs) {
1524 data.vectorStoreConfig = { ...vsConfig.config, ...data.inputs }
1525 }
1526
1527 const vStoreNodeData = _createVectorStoreNodeData(componentNodes, data, embeddingObj, undefined)
1528
1529 // Get Vector Store Instance
1530 const vectorStoreObj = await _createVectorStoreObject(componentNodes, data, vStoreNodeData)
1531 const retriever = await vectorStoreObj.init(vStoreNodeData, '', options)
1532 if (!retriever) {
1533 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Failed to create retriever`)
1534 }
1535 const startMillis = Date.now()
1536 const results = await retriever.invoke(data.query, undefined)
1537 if (!results) {
1538 throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Failed to retrieve results`)
1539 }
1540 const endMillis = Date.now()
1541 const timeTaken = endMillis - startMillis
1542 const docs: any = results.map((result: IDocument) => {
1543 return {
1544 pageContent: result.pageContent,
1545 metadata: result.metadata,
1546 id: uuidv4()

Callers

nothing calls this directly

Calls 8

getRunningExpressAppFunction · 0.90
getErrorMessageFunction · 0.90
_createEmbeddingsObjectFunction · 0.70
_createVectorStoreObjectFunction · 0.70
parseMethod · 0.65
initMethod · 0.65
invokeMethod · 0.45

Tested by

no test coverage detected