Open jacknkandy opened 1 month ago
Hey there, @jacknkandy! I'm here to help you with your technical questions and bug fixes. Let's tackle this issue together while we wait for a human maintainer to jump in.
To resolve the error related to faiss-node
in your Azure Web App service, follow these steps:
Install faiss-node
:
Ensure faiss-node
is installed as a dependency:
npm install -S faiss-node
Adjust @rollup/plugin-commonjs
Configuration:
Create or update your Rollup configuration file (e.g., rollup.config.js
) to include the dynamicRequireTargets
option for @rollup/plugin-commonjs
:
import commonjs from '@rollup/plugin-commonjs';
export default {
// other Rollup configuration options
plugins: [
commonjs({
dynamicRequireTargets: [
'node_modules/faiss-node/**/*'
],
ignoreDynamicRequires: true
})
]
};
Ensure Proper Import in Code:
In your main process file (e.g., main.js
or index.js
), ensure the import of faiss-node
is handled correctly. Add the following code snippet to handle the import:
static async importFaiss(): Promise<{ IndexFlatL2: typeof IndexFlatL2 }> {
try {
const {
default: { IndexFlatL2 },
} = await import("faiss-node");
return { IndexFlatL2 };
} catch (err: any) {
throw new Error(
`Could not import faiss-node. Please install faiss-node as a dependency with, e.g. \`npm install -S faiss-node\`.\n\nError: ${err?.message}`
);
}
}
Configure Azure Web App for Native Modules:
Create a custom startup script (e.g., startup.sh
) to install any additional dependencies and set up the environment. This script can be used to install system-level dependencies that faiss-node
might require.
Example startup.sh
script:
#!/bin/bash
# Install system-level dependencies required by faiss-node
apt-get update && apt-get install -y build-essential
# Navigate to the app directory
cd /home/site/wwwroot
# Install npm dependencies
npm install
# Start the application
npm start
Ensure the script is executable:
chmod +x startup.sh
Add the custom startup script to your Azure Web App configuration:
WEBSITE_RUN_FROM_PACKAGE
1
STARTUP_COMMAND
bash startup.sh
By following these steps, you can ensure that the Azure Web App service is configured to support native modules like faiss-node
[1][2].
To continue talking to Dosu, mention @dosu.
Just an update - I switched out and set up a new Linux-based Web App and was able to get my app to run without any hiccups. I believe there is some compatibility issue with the Windows-based build of faiss-node
in Azure (potentially along the lines of https://github.com/ewfian/faiss-node/issues/25) but was unable to investigate any further.
Checked other resources
Example Code
import statement:
import { FaissStore } from '@langchain/community/vectorstores/faiss';
package.json
GitHub Actions:
Error Message and Stack Trace (if applicable)
Could not import faiss-node. Please install faiss-node as a dependency with, e.g.
npm install -S faiss-node
.\n\nError: \\?\C:\home\site\wwwroot\node_modules\faiss-node\build\Release\faiss-node.node is not a valid Win32 application.\r\n\\?\C:\home\site\wwwroot\node_modules\faiss-node\build\Release\faiss-node.nodeDescription
Hi there,
I am having issues getting a sample app to run on an Azure Web App service. I can confirm that my app is working locally fine (MacOS) but am getting the following error after having built and deployed to a Windows-based Azure Web App service.
I am deploying via a GitHub actions deployment script, and have made sure that it is being built and deployed for using a Windows-based build server.
I can see a variety of similar issues reported for AWS etc. but cannot find a solution that works for me.
https://github.com/langchain-ai/langchainjs/issues/5843 https://github.com/langchain-ai/langchainjs/issues/5164 https://github.com/langchain-ai/langchainjs/issues/4027 https://github.com/langchain-ai/langchainjs/issues/3941
My error is slightly different as it is complaining that the
faiss-node.node
file is not a valid Win32 application.I can locate the file mentioned in the path, running Node v18 on the Web App.
I have tried installing the package locally using
npm i faiss-node
via my Azure Web app, this didn't work. Additionally I tried dropping in the files from the pre-built release from faiss-node-v0.5.1-napi-v6-win32-x64.tar.gz again this didn't change anything.Any help or guidance would be appreciated!
System Info
platform: Windows langchain 0.2.10 node 18.19.1