mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 15:55:19 +00:00
I work at Firecrawl. This adds a Firecrawl page to Integrations > Data
Platforms & Frameworks: a Python recipe that crawls a site with
Firecrawl, stores the pages as Markdown chunks with their source URL in
a LanceDB table that embeds them through the embedding registry,
searches the table, and then adds web search results to the same table.
It follows the docs workflow in CONTRIBUTING.md:
- The example is a test, `docs/web-tests/py/test_firecrawl.py`, split
into five `--8<--` snippets. Like the other integration snippets that
need a provider key, it skips unless `FIRECRAWL_API_KEY` is set.
- `docs/web/snippets/firecrawl.mdx` is generated from it with `uv run
docs/web-tests/mdx_snippets_gen.py -s docs/web-tests/py -s
docs/web-tests/ts -s docs/web-tests/rs -o docs/web/snippets`. The
generator also rewrites other snippet files on current `main` without
this change, so I left those out.
- `docs/web/integrations/data/firecrawl.mdx` imports the snippets with
`<CodeBlock>` like the dlt page, and every heading has an explicit
`{#anchor}`.
- `docs/web/docs.json` adds the page at the end of the Data Platforms &
Frameworks group.
The embedding function is `sentence-transformers` with
`all-MiniLM-L6-v2`, so the recipe needs no API key besides Firecrawl's.
Each Firecrawl call passes `integration="_lancedb"`, a label that tells
Firecrawl a request came from this guide; the page says it is optional.
It needs `firecrawl-py` 4.3.3 or later.
## Testing
```
$ FIRECRAWL_API_KEY=... pytest docs/web-tests/py/test_firecrawl.py -v
test_firecrawl.py::test_firecrawl_crawl_and_search PASSED (lancedb 0.40.0, Python 3.12)
$ pytest docs/web-tests/py/test_firecrawl.py -rs (no key)
SKIPPED [1] Set FIRECRAWL_API_KEY to run this integration snippet
$ ruff format --check docs/web-tests/py/test_firecrawl.py && ruff check docs/web-tests/py/test_firecrawl.py
1 file already formatted
All checks passed!
```
Regenerating the snippets from the test produces the same
`docs/web/snippets/firecrawl.mdx`. I have not run the Mintlify site
checks (`mint validate`, broken-links), so please run them in CI or on
your side.
I drafted this with an AI coding assistant and ran the test above
myself.
102 lines
3.8 KiB
Plaintext
102 lines
3.8 KiB
Plaintext
---
|
|
title: "Firecrawl"
|
|
sidebarTitle: "Firecrawl"
|
|
description: "Crawl or search the web with Firecrawl, store the pages as Markdown chunks in a LanceDB table with an embedding function, and search them by meaning."
|
|
keywords: ["firecrawl", "web crawling", "web search", "markdown", "rag", "ingestion"]
|
|
---
|
|
|
|
import {
|
|
PyFirecrawlChunk,
|
|
PyFirecrawlCrawl,
|
|
PyFirecrawlQuery,
|
|
PyFirecrawlTable,
|
|
PyFirecrawlWebSearch,
|
|
} from '/snippets/firecrawl.mdx';
|
|
|
|
[Firecrawl](https://www.firecrawl.dev) is a web data API that turns websites into clean
|
|
Markdown. It can crawl a whole site, scrape a single page, or run a web search and return the
|
|
content of each result. That makes it a convenient source for a LanceDB table: Firecrawl
|
|
fetches and cleans the pages, and LanceDB embeds, stores, and searches them.
|
|
|
|
This page builds a small retrieval pipeline in Python. It crawls a documentation site, splits
|
|
each page into chunks, stores the chunks with their source URL in a LanceDB table that embeds
|
|
them with a local Sentence Transformers model, and then searches the table. A last step adds
|
|
web search results to the same table.
|
|
|
|
## Install {#install}
|
|
|
|
```bash
|
|
pip install lancedb firecrawl-py sentence-transformers
|
|
```
|
|
|
|
The examples use `firecrawl-py` 4.3.3 or later. Create an API key in the
|
|
[Firecrawl dashboard](https://www.firecrawl.dev/app/api-keys) and export it:
|
|
|
|
```bash
|
|
export FIRECRAWL_API_KEY="fc-..."
|
|
```
|
|
|
|
The embedding model, `all-MiniLM-L6-v2`, runs locally, so no other API key is needed.
|
|
|
|
## Crawl a site {#crawl-a-site}
|
|
|
|
`crawl` starts at a URL, follows links below it, and waits until the job finishes. `limit`
|
|
caps the number of pages, and `formats` asks for each page as Markdown. The `integration`
|
|
argument labels the requests as coming from this guide; you can leave it out.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFirecrawlCrawl}
|
|
</CodeBlock>
|
|
|
|
Each item in `crawl.data` has the page's `markdown` and a `metadata` object with fields
|
|
such as `source_url` and `title`. To fetch a single page instead of a site, call
|
|
`firecrawl.scrape(url, formats=["markdown"])`, which returns one such item.
|
|
|
|
## Split pages into chunks {#split-pages-into-chunks}
|
|
|
|
A crawled page is often longer than an embedding model reads in one pass. Split the Markdown on
|
|
blank lines and group paragraphs into chunks of about 1,000 characters, so each row covers one
|
|
topic:
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFirecrawlChunk}
|
|
</CodeBlock>
|
|
|
|
## Store the chunks in LanceDB {#store-the-chunks-in-lancedb}
|
|
|
|
Get the Sentence Transformers embedding function from the
|
|
[embedding registry](/embedding) and declare a schema with `LanceModel`. The `text` field is
|
|
the source field, so LanceDB fills in `vector` from it as rows are added. Keep `source_url`
|
|
and `title` beside each chunk so search results can point back to the page they came from.
|
|
The database goes in a new temporary directory, so each run of this step starts from an empty
|
|
database and never overwrites a table you built earlier, including the web search results
|
|
added in the last step.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFirecrawlTable}
|
|
</CodeBlock>
|
|
|
|
## Search the pages {#search-the-pages}
|
|
|
|
The table stores its embedding function, so a text query is embedded with the same model as
|
|
the rows:
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFirecrawlQuery}
|
|
</CodeBlock>
|
|
|
|
## Add web search results {#add-web-search-results}
|
|
|
|
`search` runs a web search. With `formats` set to Markdown, Firecrawl also scrapes each
|
|
result, so the results can go into the same table as the crawled pages:
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFirecrawlWebSearch}
|
|
</CodeBlock>
|
|
|
|
## Learn more {#learn-more}
|
|
|
|
- [Firecrawl documentation](https://docs.firecrawl.dev)
|
|
- [Firecrawl Python SDK](https://docs.firecrawl.dev/sdks/python)
|
|
- [Embedding functions in LanceDB](/embedding)
|