Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
将 Firecrawl 与 LlamaIndex 集成,用于 RAG 应用
npm install llamaindex @llamaindex/openai firecrawl
FIRECRAWL_API_KEY=your_firecrawl_key OPENAI_API_KEY=your_openai_key
注意: 如果使用 Node 版本低于 20,请安装 dotenv,并在代码中添加 import 'dotenv/config'。
dotenv
import 'dotenv/config'
import { Firecrawl } from 'firecrawl'; import { Document, VectorStoreIndex, Settings } from 'llamaindex'; import { OpenAI, OpenAIEmbedding } from '@llamaindex/openai'; Settings.llm = new OpenAI({ model: "gpt-4o" }); Settings.embedModel = new OpenAIEmbedding({ model: "text-embedding-3-small" }); const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY }); const crawlResult = await firecrawl.crawl('https://firecrawl.dev', { limit: 10, scrapeOptions: { formats: ['markdown'] } }); console.log(`Crawled ${crawlResult.data.length } pages`); const documents = crawlResult.data.map((page: any, i: number) => new Document({ text: page.markdown, id_: `page-${i}`, metadata: { url: page.metadata?.sourceURL } }) ); const index = await VectorStoreIndex.fromDocuments(documents); console.log('Vector index created with embeddings'); const queryEngine = index.asQueryEngine(); const response = await queryEngine.query({ query: 'What is Firecrawl and how does it work?' }); console.log('\nAnswer:', response.toString());
此页面对您有帮助吗?