mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +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.
13 lines
2.7 KiB
Plaintext
13 lines
2.7 KiB
Plaintext
{/* Auto-generated by scripts/mdx_snippets_gen.py. Do not edit manually. */}
|
|
|
|
export const PyFirecrawlChunk = "def chunk_markdown(markdown: str, max_chars: int = 1000) -> list[str]:\n chunks, current = [], \"\"\n for paragraph in markdown.split(\"\\n\\n\"):\n if current and len(current) + len(paragraph) > max_chars:\n chunks.append(current.strip())\n current = \"\"\n current += paragraph + \"\\n\\n\"\n if current.strip():\n chunks.append(current.strip())\n return chunks\n";
|
|
|
|
export const PyFirecrawlCrawl = "import os\n\nfrom firecrawl import Firecrawl\n\nfirecrawl = Firecrawl(api_key=os.environ[\"FIRECRAWL_API_KEY\"])\n\ncrawl = firecrawl.crawl(\n \"https://docs.lancedb.com/enterprise/v1-14-0/integrations\",\n limit=10,\n scrape_options={\"formats\": [\"markdown\"], \"only_main_content\": True},\n integration=\"_lancedb\",\n)\npages = [page for page in crawl.data if page.markdown]\nprint(f\"Crawled {len(pages)} pages\")\n";
|
|
|
|
export const PyFirecrawlQuery = "results = (\n table.search(\"How do I query a LanceDB table with SQL?\")\n .select([\"title\", \"source_url\", \"text\", \"_distance\"])\n .limit(3)\n .to_list()\n)\nfor row in results:\n print(f\"{row['_distance']:.3f}\", row[\"source_url\"])\n";
|
|
|
|
export const PyFirecrawlTable = "import tempfile\n\nimport lancedb\nfrom lancedb.embeddings import get_registry\nfrom lancedb.pydantic import LanceModel, Vector\n\nembedder = (\n get_registry().get(\"sentence-transformers\").create(name=\"all-MiniLM-L6-v2\")\n)\n\nclass WebChunk(LanceModel):\n text: str = embedder.SourceField()\n vector: Vector(embedder.ndims()) = embedder.VectorField()\n source_url: str\n title: str\n\nrows = [\n {\n \"text\": chunk,\n \"source_url\": page.metadata.source_url,\n \"title\": page.metadata.title or \"\",\n }\n for page in pages\n for chunk in chunk_markdown(page.markdown)\n]\n\ndb = lancedb.connect(tempfile.mkdtemp(prefix=\"lancedb-firecrawl-\"))\ntable = db.create_table(\"firecrawl_docs\", schema=WebChunk)\ntable.add(rows)\nprint(f\"Added {table.count_rows()} chunks\")\n";
|
|
|
|
export const PyFirecrawlWebSearch = "search = firecrawl.search(\n \"lancedb hybrid search reranking\",\n limit=5,\n scrape_options={\"formats\": [\"markdown\"], \"only_main_content\": True},\n integration=\"_lancedb\",\n)\ntable.add(\n [\n {\n \"text\": chunk,\n \"source_url\": result.metadata.source_url,\n \"title\": result.metadata.title or \"\",\n }\n for result in search.web or []\n if getattr(result, \"markdown\", None)\n for chunk in chunk_markdown(result.markdown)\n ]\n)\nprint(f\"Table now holds {table.count_rows()} chunks\")\n";
|
|
|