Skip to main content

Vector embeddings generation and storage for Scrapy

Project description

scrapy-vectors

Tests Code Quality Python 3.9+ License: ISC PyPI version

Vector embeddings generation and storage for Scrapy spiders.

Features

  • Embeddings Pipeline: Generate vector embeddings using LiteLLM (supports OpenAI, Cohere, and other providers)
  • S3 Vectors Storage: Store embeddings in AWS S3 Vectors service

Platform Support

Supported Platforms:

  • Linux - Fully supported
  • macOS - Fully supported
  • Windows - Not supported (requires uvloop to use litellm[proxy], which is Unix-only)

Installation

pip install scrapy-vectors

Quick Start

In your scrapy_settings.py:

ITEM_PIPELINES = {
    # Outputs as jsonlines in Pinecone format, which s3-vectors can use
    "scrapy_vectors.EmbeddingsLiteLLMPipeline": 300,
}
EXTENSIONS = {
    "scrapy.extensions.feedexport.FeedExporter": None,  # Disable standard
    "scrapy_vectors.S3VectorsFeedExporter": 300,        # Use custom
}
FEED_STORAGES = {
    "s3-vectors": "scrapy_vectors.S3VectorsFeedStorage",
}
FEEDS = {
    "s3-vectors://vectors-bucket/vectors-index": {
        "format": "jsonlines",
        "batch_item_count": 100,
    }
}

# LiteLLM will route for you
LITELLM_API_KEY = "your_provider_api_key"          # (e.g. OpenAI API Key)
LITELLM_EMBEDDING_MODEL = "text-embedding-3-small" # This is default when unspecified

AWS_REGION_NAME = "us-east-1"
AWS_ACCESS_KEY_ID = "access_key_id"
AWS_SECRET_ACCESS_KEY = "access_key"

In your scraper:

import scrapy


class MySpider(scrapy.Spider):
    name = "example"
    start_urls = ["https://example.com"]

    # Must yield with: id, page_content, and metadata
    def parse(self, response):
        yield {
            "id": response.url,
            "page_content": response.css("article::text").get(),
            "metadata": {
                "title": response.css("h1::text").get(),
                "url": response.url,
            }
        }

Configuration

Embeddings Pipeline Settings

  • LITELLM_API_KEY: API key for your embedding provider (required)
  • LITELLM_EMBEDDING_MODEL: Model to use (default: OpenAI's text-embedding-3-small)

S3 Vectors Storage Settings

  • AWS_REGION_NAME: AWS region (required)
  • AWS_ACCESS_KEY_ID: AWS access key
  • AWS_SECRET_ACCESS_KEY: AWS secret key

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_vectors-0.2.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_vectors-0.2.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file scrapy_vectors-0.2.2.tar.gz.

File metadata

  • Download URL: scrapy_vectors-0.2.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for scrapy_vectors-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4093e90d4bf77ab301b7404265024450194eb3de9ad87f4501830d0b213da94f
MD5 849bbcba373c8e5be8214b4c11c18369
BLAKE2b-256 364b9717fcd50adb28d132abaaa9879686595c4e5f4fcc682fb38279d37dd824

See more details on using hashes here.

File details

Details for the file scrapy_vectors-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: scrapy_vectors-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for scrapy_vectors-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8066c088ef6744aff711926d0197fb9622c753923eb25edeb509f69c05036ab3
MD5 6f941593978118434ae000db55fc6a53
BLAKE2b-256 b976d6a2b6c992245d61724f28d8cfee2a0af4ae552ae3e6315d4dfcc73ed6fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page