--- title: Apache Spark aliases: [ ../integrations/spark/, ../frameworks/spark/ ] --- # Apache Spark [Spark](https://spark.apache.org/) is a distributed computing framework designed for big data processing and analytics. The [Qdrant-Spark connector](https://github.com/qdrant/qdrant-spark) enables Qdrant to be a storage destination in Spark. ## Installation You can set up the Qdrant-Spark Connector in a few different ways, depending on your preferences and requirements. ### GitHub Releases You can download the packaged JAR file from the [GitHub releases](https://github.com/qdrant/qdrant-spark/releases). It comes with all the required dependencies. ### Building from Source To build the JAR from source, you'll need [JDK 8](https://www.azul.com/downloads/#zulu) and [Maven](https://maven.apache.org/) installed on your system. Once you have those in place, navigate to the project's root directory and run the following command: ```bash mvn package -DskipTests ``` This will compile the source code and generate a fat JAR, which will be stored in the `target` directory by default. ### Maven Central The package can be found [here](https://central.sonatype.com/artifact/io.qdrant/spark). ## Usage Below, we'll walk through the steps of creating a Spark session and ingesting data into Qdrant. To begin, import the necessary libraries and create a Spark session with Qdrant support: ```python from pyspark.sql import SparkSession spark = SparkSession.builder.config( "spark.jars", "spark-VERSION.jar", # Specify the path to the downloaded JAR file ) .master("local[*]") .appName("qdrant") .getOrCreate() ``` ```scala import org.apache.spark.sql.SparkSession val spark = SparkSession.builder .config("spark.jars", "spark-VERSION.jar") // Specify the path to the downloaded JAR file .master("local[*]") .appName("qdrant") .getOrCreate() ``` ```java import org.apache.spark.sql.SparkSession; public class QdrantSparkJavaExample { public static void main(String[] args) { SparkSession spark = SparkSession.builder() .config("spark.jars", "spark-VERSION.jar") // Specify the path to the downloaded JAR file .master("local[*]") .appName("qdrant") .getOrCreate(); } } ``` The connector supports ingesting multiple named/unnamed, dense/sparse vectors. _Click each to expand._
Unnamed/Default vector ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", ) .option("collection_name", ) .option("embedding_field", ) # Expected to be a field of type ArrayType(FloatType) .option("schema", .schema.json()) .mode("append") .save() ```
Named vector ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", ) .option("collection_name", ) .option("embedding_field", ) # Expected to be a field of type ArrayType(FloatType) .option("vector_name", ) .option("schema", .schema.json()) .mode("append") .save() ``` > #### NOTE > > The `embedding_field` and `vector_name` options are maintained for backward compatibility. It is recommended to use `vector_fields` and `vector_names` for named vectors as shown below.
Multiple named vectors ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", "") .option("collection_name", "") .option("vector_fields", ",") .option("vector_names", ",") .option("schema", .schema.json()) .mode("append") .save() ```
Sparse vectors ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", "") .option("collection_name", "") .option("sparse_vector_value_fields", "") .option("sparse_vector_index_fields", "") .option("sparse_vector_names", "") .option("schema", .schema.json()) .mode("append") .save() ```
Multiple sparse vectors ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", "") .option("collection_name", "") .option("sparse_vector_value_fields", ",") .option("sparse_vector_index_fields", ",") .option("sparse_vector_names", ",") .option("schema", .schema.json()) .mode("append") .save() ```
Combination of named dense and sparse vectors ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", "") .option("collection_name", "") .option("vector_fields", ",") .option("vector_names", ",") .option("sparse_vector_value_fields", ",") .option("sparse_vector_index_fields", ",") .option("sparse_vector_names", ",") .option("schema", .schema.json()) .mode("append") .save() ```
No vectors - Entire dataframe is stored as payload ```python .write .format("io.qdrant.spark.Qdrant") .option("qdrant_url", "") .option("collection_name", "") .option("schema", .schema.json()) .mode("append") .save() ```
## Databricks You can use the `qdrant-spark` connector as a library in [Databricks](https://www.databricks.com/). - Go to the `Libraries` section in your Databricks cluster dashboard. - Select `Install New` to open the library installation modal. - Search for `io.qdrant:spark:VERSION` in the Maven packages and click `Install`. ![Databricks](/documentation/frameworks/spark/databricks.png) ## Datatype Support Qdrant supports most Spark data types, and the appropriate data types are mapped based on the provided schema. ## Configuration Options | Option | Description | Column DataType | Required | | :--------------------------- | :------------------------------------------------------------------ | :---------------------------- | :------- | | `qdrant_url` | GRPC URL of the Qdrant instance. Eg: | - | ✅ | | `collection_name` | Name of the collection to write data into | - | ✅ | | `schema` | JSON string of the dataframe schema | - | ✅ | | `embedding_field` | Name of the column holding the embeddings | `ArrayType(FloatType)` | ❌ | | `id_field` | Name of the column holding the point IDs. Default: Random UUID | `StringType` or `IntegerType` | ❌ | | `batch_size` | Max size of the upload batch. Default: 64 | - | ❌ | | `retries` | Number of upload retries. Default: 3 | - | ❌ | | `api_key` | Qdrant API key for authentication | - | ❌ | | `vector_name` | Name of the vector in the collection. | - | ❌ | | `vector_fields` | Comma-separated names of columns holding the vectors. | `ArrayType(FloatType)` | ❌ | | `vector_names` | Comma-separated names of vectors in the collection. | - | ❌ | | `sparse_vector_index_fields` | Comma-separated names of columns holding the sparse vector indices. | `ArrayType(IntegerType)` | ❌ | | `sparse_vector_value_fields` | Comma-separated names of columns holding the sparse vector values. | `ArrayType(FloatType)` | ❌ | | `sparse_vector_names` | Comma-separated names of the sparse vectors in the collection. | - | ❌ | | `shard_key_selector` | Comma-separated names of custom shard keys to use during upsert. | - | ❌ | For more information, be sure to check out the [Qdrant-Spark GitHub repository](https://github.com/qdrant/qdrant-spark). The Apache Spark guide is available [here](https://spark.apache.org/docs/latest/quick-start.html). Happy data processing!