### Install dependencies Source: https://qdrant.github.io/fastembed/examples/Hybrid_Search Installs required packages: qdrant-client, fastembed, datasets, transformers. ```bash !pip install -qU qdrant-client fastembed datasets transformers ``` -------------------------------- ### Install FastEmbed with pip Source: https://qdrant.github.io/fastembed Install the FastEmbed library using pip. ```bash pip install fastembed ``` -------------------------------- ### Prepare example documents Source: https://qdrant.github.io/fastembed/qdrant/Usage_With_Qdrant Defines a list of example documents about Maharana Pratap. These documents will be embedded and added to the Qdrant collection. ```python # Example list of documents documents: list[str] = [ "Maharana Pratap was a Rajput warrior king from Mewar", "He fought against the Mughal Empire led by Akbar", "The Battle of Haldighati in 1576 was his most famous battle", "He refused to submit to Akbar and continued guerrilla warfare", "His capital was Chittorgarh, which he lost to the Mughals", "He died in 1597 at the age of 57", "Maharana Pratap is considered a symbol of Rajput resistance against foreign rule", "His legacy is celebrated in Rajasthan through festivals and monuments", "He had 11 wives and 17 sons, including Amar Singh I who succeeded him as ruler of Mewar", "His life has been depicted in various films, TV shows, and books", ] ``` -------------------------------- ### Install dependencies with pip Source: https://qdrant.github.io/fastembed/examples/FastEmbed_vs_HF_Comparison Installs matplotlib, transformers, and torch using pip with the -qq flag to suppress output. ```bash !pip install matplotlib transformers torch -qq ``` -------------------------------- ### Install dependencies with pip Source: https://qdrant.github.io/fastembed/examples/Hindi_Tamil_RAG_with_Navarasa7B Install required packages for the notebook: fastembed, datasets, qdrant-client, peft, transformers, accelerate, and bitsandbytes. Run this in a Colab or local environment before proceeding. ```bash !pip install -U fastembed datasets qdrant-client peft transformers accelerate bitsandbytes -qq ``` -------------------------------- ### Install FastEmbed Source: https://qdrant.github.io/fastembed/qdrant/Retrieval_with_FastEmbed Install the fastembed package to create embeddings and perform retrieval. ```bash # !pip install fastembed --quiet --upgrade ``` -------------------------------- ### Install onnxruntime-gpu for CUDA 11.x Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Install the latest onnxruntime-gpu with CUDA 11.x support. Ensure CuDNN 9.x is installed. ```bash !pip install onnxruntime-gpu -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-11/pypi/simple/ -qq ``` -------------------------------- ### Install fastembed-gpu Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Install the fastembed-gpu package, which substitutes onnxruntime with onnxruntime-gpu. Note that onnxruntime-gpu and onnxruntime cannot coexist in the same environment. ```bash !pip install fastembed-gpu ``` -------------------------------- ### Install Qdrant Client with FastEmbed Source: https://qdrant.github.io/fastembed Install the Qdrant client with FastEmbed support using pip. On zsh, you may need to quote the package name. ```bash pip install qdrant-client[fastembed] ``` -------------------------------- ### Install dependencies with pip Source: https://qdrant.github.io/fastembed/qdrant/Binary_Quantization_with_Qdrant Installs the required Python packages: qdrant-client, pandas, and dataset. The --quiet and --upgrade flags suppress output and upgrade existing packages. ```bash !pip install qdrant-client pandas dataset --quiet --upgrade ``` -------------------------------- ### Install CUDA 12.x on Ubuntu 22.04 Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Download and install the CUDA toolkit for Ubuntu 22.04 x86_64. After installation, set LD_LIBRARY_PATH to /usr/local/cuda/lib64. ```bash wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt-get update sudo apt-get -y install cuda ``` -------------------------------- ### Install fastembed with pip Source: https://qdrant.github.io/fastembed/Getting%20Started Install the fastembed package using pip with the -Uqq flags for quiet upgrade. ```bash !pip install -Uqq fastembed ``` -------------------------------- ### Install dependencies for binary quantization Source: https://qdrant.github.io/fastembed/experimental/Binary%20Quantization%20from%20Scratch Installs required Python packages: matplotlib, tqdm, pandas, numpy, and datasets. ```bash !pip install matplotlib tqdm pandas numpy datasets --quiet --upgrade ``` -------------------------------- ### Use FastEmbed with Qdrant Source: https://qdrant.github.io/fastembed Initialize an in-process Qdrant client, add documents with metadata and IDs, and query the collection using text. The example shows how to add documents and perform a text search. ```python from qdrant_client import QdrantClient # Initialize the client client = QdrantClient(":memory:") # Using an in-process Qdrant # Prepare your documents, metadata, and IDs docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"] metadata = [ {"source": "Langchain-docs"}, {"source": "Llama-index-docs"}, ] ids = [42, 2] client.add( collection_name="demo_collection", documents=docs, metadata=metadata, ids=ids ) search_result = client.query( collection_name="demo_collection", query_text="This is a query document" ) print(search_result) ``` -------------------------------- ### Error: CuDNN library not installed Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Common error when CuDNN library is missing: libcudnn.so.x cannot be found. ```text FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcudnn.so.x: cannot open shared object file: No such file or directory ``` -------------------------------- ### Error: CUDA library not installed Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Common error when CUDA library is missing: libcublasLt.so.x cannot be found. ```text FAIL : Failed to load library libonnxruntime_providers_cuda.so with error: libcublasLt.so.x: cannot open shared object file: No such file or directory ``` -------------------------------- ### Load and filter the ESCI dataset Source: https://qdrant.github.io/fastembed/examples/Hybrid_Search Loads the tasksource/esci dataset, selects the first 1000 examples, and filters to product_locale == 'us', resulting in 919 rows. ```python dataset = load_dataset("tasksource/esci", split="train") # We'll select the first 1000 examples for this demo dataset = dataset.select(range(1000)) dataset = dataset.filter(lambda x: x["product_locale"] == "us") dataset ``` ```python Dataset({ features: ['example_id', 'query', 'query_id', 'product_id', 'product_locale', 'esci_label', 'small_version', 'large_version', 'product_title', 'product_description', 'product_bullet_point', 'product_brand', 'product_color', 'product_text'], num_rows: 919 }) ``` -------------------------------- ### Install fastembed-gpu with onnxruntime-gpu 1.18.0 for CuDNN 8 Source: https://qdrant.github.io/fastembed/examples/FastEmbed_GPU Lock onnxruntime-gpu to 1.18.0 with CUDA 12.x to work with CuDNN 8, then install fastembed-gpu. ```bash !pip install onnxruntime-gpu==1.18.0 -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-cuda-12/pypi/simple/ -qq !pip install fastembed-gpu -qqq ``` -------------------------------- ### Import libraries and set random seeds Source: https://qdrant.github.io/fastembed/qdrant/Binary_Quantization_with_Qdrant Imports the necessary libraries and sets random seeds for reproducibility. The time module is imported but not used in the subsequent examples. ```python import os import random import time import datasets import numpy as np import pandas as pd from qdrant_client import QdrantClient, models random.seed(37) np.random.seed(37) ``` -------------------------------- ### Initialize FastEmbed TextEmbedding with default model Source: https://qdrant.github.io/fastembed/examples/FastEmbed_vs_HF_Comparison Initializes a FastEmbed TextEmbedding instance using the same model ID as the HuggingFace example. The output shows a warning about tokenizers parallelism and a progress bar for fetching model files. ```python embedding_model = TextEmbedding(model_name=model_id) ``` ```text huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks... To disable this warning, you can either: - Avoid using `tokenizers` before the fork if possible - Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false) ``` ```text Fetching 9 files: 0%| | 0/9 [00:00