FalkorDBVectorStore
FalkorDB is an open-source graph database with integrated support for vector similarity search
it supports:
- approximate nearest neighbor search
- Euclidean similarity & Cosine Similarity
- Hybrid search combining vector and keyword searches
This notebook shows how to use the FalkorDB vector index (FalkorDB
)
See the installation instruction
Setupโ
# Pip install necessary package
%pip install --upgrade falkordb
%pip install --upgrade tiktoken
%pip install --upgrade langchain langchain_huggingface
Requirement already satisfied: falkordb in /home/atary/langchain/.venv/lib/python3.10/site-packages (1.0.8)
Requirement already satisfied: redis<6.0.0,>=5.0.1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from falkordb) (5.1.0)
Requirement already satisfied: async-timeout>=4.0.3 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from redis<6.0.0,>=5.0.1->falkordb) (4.0.3)
Note: you may need to restart the kernel to use updated packages.
Requirement already satisfied: tiktoken in /home/atary/langchain/.venv/lib/python3.10/site-packages (0.7.0)
Requirement already satisfied: regex>=2022.1.18 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from tiktoken) (2024.9.11)
Requirement already satisfied: requests>=2.26.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from tiktoken) (2.32.3)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests>=2.26.0->tiktoken) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests>=2.26.0->tiktoken) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests>=2.26.0->tiktoken) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests>=2.26.0->tiktoken) (2024.8.30)
Note: you may need to restart the kernel to use updated packages.
Requirement already satisfied: langchain in /home/atary/langchain/.venv/lib/python3.10/site-packages (0.3.0)
Collecting langchain
Using cached langchain-0.3.1-py3-none-any.whl.metadata (7.1 kB)
Collecting langchain_huggingface
Using cached langchain_huggingface-0.1.0-py3-none-any.whl.metadata (1.3 kB)
Requirement already satisfied: PyYAML>=5.3 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (6.0.2)
Requirement already satisfied: SQLAlchemy<3,>=1.4 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (2.0.35)
Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (3.10.5)
Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (4.0.3)
Collecting langchain-core<0.4.0,>=0.3.6 (from langchain)
Using cached langchain_core-0.3.7-py3-none-any.whl.metadata (6.3 kB)
Requirement already satisfied: langchain-text-splitters<0.4.0,>=0.3.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (0.3.0)
Requirement already satisfied: langsmith<0.2.0,>=0.1.17 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (0.1.121)
Requirement already satisfied: numpy<2,>=1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (1.26.4)
Requirement already satisfied: pydantic<3.0.0,>=2.7.4 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (2.9.1)
Requirement already satisfied: requests<3,>=2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (2.32.3)
Requirement already satisfied: tenacity!=8.4.0,<9.0.0,>=8.1.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain) (8.5.0)
Collecting huggingface-hub>=0.23.0 (from langchain_huggingface)
Using cached huggingface_hub-0.25.1-py3-none-any.whl.metadata (13 kB)
Collecting sentence-transformers>=2.6.0 (from langchain_huggingface)
Using cached sentence_transformers-3.1.1-py3-none-any.whl.metadata (10 kB)
Collecting tokenizers>=0.19.1 (from langchain_huggingface)
Using cached tokenizers-0.20.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)
Collecting transformers>=4.39.0 (from langchain_huggingface)
Using cached transformers-4.45.1-py3-none-any.whl.metadata (44 kB)
Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (2.4.0)
Requirement already satisfied: aiosignal>=1.1.2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (24.2.0)
Requirement already satisfied: frozenlist>=1.1.1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.1)
Requirement already satisfied: multidict<7.0,>=4.5 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.1.0)
Requirement already satisfied: yarl<2.0,>=1.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.11.1)
Collecting filelock (from huggingface-hub>=0.23.0->langchain_huggingface)
Using cached filelock-3.16.1-py3-none-any.whl.metadata (2.9 kB)
Collecting fsspec>=2023.5.0 (from huggingface-hub>=0.23.0->langchain_huggingface)
Using cached fsspec-2024.9.0-py3-none-any.whl.metadata (11 kB)
Requirement already satisfied: packaging>=20.9 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from huggingface-hub>=0.23.0->langchain_huggingface) (24.1)
Requirement already satisfied: tqdm>=4.42.1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from huggingface-hub>=0.23.0->langchain_huggingface) (4.66.5)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from huggingface-hub>=0.23.0->langchain_huggingface) (4.12.2)
Requirement already satisfied: jsonpatch<2.0,>=1.33 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langchain-core<0.4.0,>=0.3.6->langchain) (1.33)
Collecting langsmith<0.2.0,>=0.1.17 (from langchain)
Using cached langsmith-0.1.129-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: httpx<1,>=0.23.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langsmith<0.2.0,>=0.1.17->langchain) (0.27.2)
Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from langsmith<0.2.0,>=0.1.17->langchain) (3.10.7)
Requirement already satisfied: annotated-types>=0.6.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (0.7.0)
Requirement already satisfied: pydantic-core==2.23.3 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.7.4->langchain) (2.23.3)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests<3,>=2->langchain) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests<3,>=2->langchain) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests<3,>=2->langchain) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from requests<3,>=2->langchain) (2024.8.30)
Collecting torch>=1.11.0 (from sentence-transformers>=2.6.0->langchain_huggingface)
Using cached torch-2.4.1-cp310-cp310-manylinux1_x86_64.whl.metadata (26 kB)
Collecting scikit-learn (from sentence-transformers>=2.6.0->langchain_huggingface)
Using cached scikit_learn-1.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (13 kB)
Collecting scipy (from sentence-transformers>=2.6.0->langchain_huggingface)
Using cached scipy-1.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
Collecting Pillow (from sentence-transformers>=2.6.0->langchain_huggingface)
Using cached pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl.metadata (9.2 kB)
Requirement already satisfied: greenlet!=0.4.17 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from SQLAlchemy<3,>=1.4->langchain) (3.1.0)
Requirement already satisfied: regex!=2019.12.17 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from transformers>=4.39.0->langchain_huggingface) (2024.9.11)
Collecting safetensors>=0.4.1 (from transformers>=4.39.0->langchain_huggingface)
Using cached safetensors-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)
Requirement already satisfied: anyio in /home/atary/langchain/.venv/lib/python3.10/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain) (4.4.0)
Requirement already satisfied: httpcore==1.* in /home/atary/langchain/.venv/lib/python3.10/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain) (1.0.5)
Requirement already satisfied: sniffio in /home/atary/langchain/.venv/lib/python3.10/site-packages (from httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain) (1.3.1)
Requirement already satisfied: h11<0.15,>=0.13 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain) (0.14.0)
Requirement already satisfied: jsonpointer>=1.9 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.4.0,>=0.3.6->langchain) (3.0.0)
Collecting sympy (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached sympy-1.13.3-py3-none-any.whl.metadata (12 kB)
Collecting networkx (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached networkx-3.3-py3-none-any.whl.metadata (5.1 kB)
Requirement already satisfied: jinja2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface) (3.1.4)
Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cublas-cu12==12.1.3.1 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cufft-cu12==11.0.2.54 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-curand-cu12==10.3.2.106 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-nccl-cu12==2.20.5 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl.metadata (1.8 kB)
Collecting nvidia-nvtx-cu12==12.1.105 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.7 kB)
Collecting triton==3.0.0 (from torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (1.3 kB)
Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached nvidia_nvjitlink_cu12-12.6.77-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)
Collecting joblib>=1.2.0 (from scikit-learn->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached joblib-1.4.2-py3-none-any.whl.metadata (5.4 kB)
Collecting threadpoolctl>=3.1.0 (from scikit-learn->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached threadpoolctl-3.5.0-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: exceptiongroup>=1.0.2 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from anyio->httpx<1,>=0.23.0->langsmith<0.2.0,>=0.1.17->langchain) (1.2.2)
Requirement already satisfied: MarkupSafe>=2.0 in /home/atary/langchain/.venv/lib/python3.10/site-packages (from jinja2->torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface) (2.1.5)
Collecting mpmath<1.4,>=1.1.0 (from sympy->torch>=1.11.0->sentence-transformers>=2.6.0->langchain_huggingface)
Using cached mpmath-1.3.0-py3-none-any.whl.metadata (8.6 kB)
Using cached langchain-0.3.1-py3-none-any.whl (1.0 MB)
Using cached langchain_huggingface-0.1.0-py3-none-any.whl (20 kB)
Using cached huggingface_hub-0.25.1-py3-none-any.whl (436 kB)
Using cached langchain_core-0.3.7-py3-none-any.whl (400 kB)
Using cached langsmith-0.1.129-py3-none-any.whl (292 kB)
Using cached sentence_transformers-3.1.1-py3-none-any.whl (245 kB)
Using cached tokenizers-0.20.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB)
Using cached transformers-4.45.1-py3-none-any.whl (9.9 MB)
Using cached fsspec-2024.9.0-py3-none-any.whl (179 kB)
Using cached safetensors-0.4.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (435 kB)
Using cached torch-2.4.1-cp310-cp310-manylinux1_x86_64.whl (797.1 MB)
Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m410.6/410.6 MB[0m [31m1.9 MB/s[0m eta [36m0:00:00[0m00:01[0m00:06[0m
[?25hDownloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m14.1/14.1 MB[0m [31m3.1 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hDownloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m23.7/23.7 MB[0m [31m3.2 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m823.6/823.6 kB[0m [31m3.2 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hDownloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m664.8/664.8 MB[0m [31m1.8 MB/s[0m eta [36m0:00:00[0m00:01[0m00:05[0m
[?25hDownloading nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m121.6/121.6 MB[0m [31m2.5 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m56.5/56.5 MB[0m [31m2.1 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m124.2/124.2 MB[0m [31m2.2 MB/s[0m eta [36m0:00:00[0m00:01[0m00:02[0m
[?25hDownloading nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m196.0/196.0 MB[0m [31m2.0 MB/s[0m eta [36m0:00:00[0m00:01[0m00:02[0m
[?25hDownloading nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m176.2/176.2 MB[0m [31m1.7 MB/s[0m eta [36m0:00:00[0m00:01[0m00:03[0m
[?25hDownloading nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)
Downloading triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (209.4 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m209.4/209.4 MB[0m [31m1.7 MB/s[0m eta [36m0:00:00[0m00:01[0m00:03[0m
[?25hUsing cached filelock-3.16.1-py3-none-any.whl (16 kB)
Downloading pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m4.5/4.5 MB[0m [31m1.9 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading scikit_learn-1.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m13.3/13.3 MB[0m [31m2.1 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading scipy-1.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.2 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m41.2/41.2 MB[0m [31m2.6 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hDownloading joblib-1.4.2-py3-none-any.whl (301 kB)
Downloading threadpoolctl-3.5.0-py3-none-any.whl (18 kB)
Downloading networkx-3.3-py3-none-any.whl (1.7 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m1.7/1.7 MB[0m [31m1.0 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hDownloading sympy-1.13.3-py3-none-any.whl (6.2 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m6.2/6.2 MB[0m [31m2.7 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hDownloading mpmath-1.3.0-py3-none-any.whl (536 kB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m536.2/536.2 kB[0m [31m2.4 MB/s[0m eta [36m0:00:00[0m
[?25hDownloading nvidia_nvjitlink_cu12-12.6.77-py3-none-manylinux2014_x86_64.whl (19.7 MB)
[2K [90mโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[0m [32m19.7/19.7 MB[0m [31m2.5 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hInstalling collected packages: mpmath, threadpoolctl, sympy, scipy, safetensors, Pillow, nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, networkx, joblib, fsspec, filelock, triton, scikit-learn, nvidia-cusparse-cu12, nvidia-cudnn-cu12, huggingface-hub, tokenizers, nvidia-cusolver-cu12, langsmith, transformers, torch, langchain-core, sentence-transformers, langchain_huggingface, langchain
Attempting uninstall: langsmith
Found existing installation: langsmith 0.1.121
Uninstalling langsmith-0.1.121:
Successfully uninstalled langsmith-0.1.121
Attempting uninstall: langchain-core
Found existing installation: langchain-core 0.3.0
Uninstalling langchain-core-0.3.0:
Successfully uninstalled langchain-core-0.3.0
Attempting uninstall: langchain
Found existing installation: langchain 0.3.0
Uninstalling langchain-0.3.0:
Successfully uninstalled langchain-0.3.0
Successfully installed Pillow-10.4.0 filelock-3.16.1 fsspec-2024.9.0 huggingface-hub-0.25.1 joblib-1.4.2 langchain-0.3.1 langchain-core-0.3.7 langchain_huggingface-0.1.0 langsmith-0.1.129 mpmath-1.3.0 networkx-3.3 nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.6.77 nvidia-nvtx-cu12-12.1.105 safetensors-0.4.5 scikit-learn-1.5.2 scipy-1.14.1 sentence-transformers-3.1.1 sympy-1.13.3 threadpoolctl-3.5.0 tokenizers-0.20.0 torch-2.4.1 transformers-4.45.1 triton-3.0.0
Note: you may need to restart the kernel to use updated packages.
Credentialsโ
We want to use OpenAIEmbeddings
so we have to get the OpenAI API Key
import getpass
import os
if "HUGGINGFACE_API_KEY" not in os.environ:
os.environ["HUGGINGFACE_API_KEY"] = getpass.getpass("HuggingFace API Key:")
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
Initializationโ
from langchain_community.vectorstores.falkordb_vector import FalkorDBVector
from langchain_core.documents import Document
from langchain_huggingface import HuggingFaceEmbeddings
You can use FalkorDBVector locally with docker. See installation instruction
host = 'localhost'
port = 6379
Or you can use FalkorDBVector with FalkorDB Cloud
# E.g
# host = "r-6jissuruar.instance-zwb082gpf.hc-v8noonp0c.europe-west1.gcp.f2e0a955bb84.cloud"
# port = 62471
# username = "falkordb" # SET ON FALKORDB CLOUD
# password = "password" # SET ON FALKORDB CLOUD
vector_store = FalkorDBVector(host=host, port=port, embedding=HuggingFaceEmbeddings())
model.safetensors: 45%|####5 | 199M/438M [00:00<?, ?B/s]
tokenizer_config.json: 0%| | 0.00/363 [00:00<?, ?B/s]
vocab.txt: 0%| | 0.00/232k [00:00<?, ?B/s]
tokenizer.json: 0%| | 0.00/466k [00:00<?, ?B/s]
special_tokens_map.json: 0%| | 0.00/239 [00:00<?, ?B/s]
/home/atary/langchain/.venv/lib/python3.10/site-packages/transformers/tokenization_utils_base.py:1617: FutureWarning: `clean_up_tokenization_spaces` was not set. It will be set to `True` by default. This behavior will be deprecated in transformers v4.45, and will be then set to `False` by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884
warnings.warn(
1_Pooling/config.json: 0%| | 0.00/190 [00:00<?, ?B/s]
Manage vector storeโ
Add items to vector storeโ
from langchain_core.documents import Document
document_1 = Document(
page_content="foo",
metadata={"source": "https://example.com"}
)
document_2 = Document(
page_content="bar",
metadata={"source": "https://example.com"}
)
document_3 = Document(
page_content="baz",
metadata={"source": "https://example.com"}
)
documents = [document_1, document_2, document_3]
vector_store.add_documents(documents=documents,ids=["1","2","3"])
['1', '2', '3']
Update items in vector storeโ
updated_document = Document(
page_content="qux",
metadata={"source": "https://another-example.com"}
)
vector_store.update_documents(document_id="1",document=updated_document)
Delete items from vector storeโ
vector_store.delete(ids=["3"])
Query vector storeโ
Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.
Query directlyโ
Performing a simple similarity search can be done as follows:
results = vector_store.similarity_search(query="thud",k=1,filter={"source":"https://another-example.com"})
for doc in results:
print(f"* {doc.page_content} [{doc.metadata}]")
* qux [{'text': 'qux', 'id': '1', 'source': 'https://another-example.com'}]
If you want to execute a similarity search and receive the corresponding scores you can run:
results = vector_store.similarity_search_with_score(query="bar")
for doc, score in results:
print(f"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]")
* [SIM=0.000001] bar [{'text': 'bar', 'id': '2', 'source': 'https://example.com'}]
Query by turning into retrieverโ
You can also transform the vector store into a retriever for easier usage in your chains.
retriever = vector_store.as_retriever(
search_type="mmr",
search_kwargs={"k": 1}
)
retriever.invoke("thud")
[Document(metadata={'text': 'qux', 'id': '1', 'source': 'https://another-example.com'}, page_content='qux')]
Usage for retrieval-augmented generationโ
For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:
- Tutorials: working with external knowledge
- How-to: Question and answer with RAG
- Retrieval conceptual docs
API referenceโ
For detailed documentation of all FalkorDB__VectorStore features and configurations head to the API reference: https://api.python.langchain.com/en/latest/vectorstores/__module_name.vectorstores.__FalkorDB__VectorStore.html
Relatedโ
- Vector store conceptual guide
- Vector store how-to guides