cboettig commited on
Commit
022d1be
·
1 Parent(s): bb9c2bf

Better embedding, better prompt, tidy up :broom:

Browse files
Files changed (3) hide show
  1. .gitignore +4 -0
  2. src/app.py +24 -37
  3. vllm-tutorial.ipynb +380 -128
.gitignore CHANGED
@@ -175,3 +175,7 @@ cython_debug/
175
 
176
  *.pdf
177
 
 
 
 
 
 
175
 
176
  *.pdf
177
 
178
+ *.lock
179
+ *.db
180
+ *.sqlite
181
+
src/app.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- from langchain_community.document_loaders import PyPDFLoader
3
 
4
  ## dockerized streamlit app wants to read from os.getenv(), otherwise use st.secrets
5
  import os
@@ -17,20 +16,8 @@ st.title("HWC LLM Testing")
17
  (Demo will take a while to load first while processing all data! Will be pre-processed in future...)
18
  '''
19
 
20
- # +
21
- import bs4
22
- from langchain import hub
23
- from langchain_chroma import Chroma
24
- from langchain_community.document_loaders import WebBaseLoader
25
- from langchain_core.output_parsers import StrOutputParser
26
- from langchain_core.runnables import RunnablePassthrough
27
- from langchain_openai import OpenAIEmbeddings
28
- from langchain_text_splitters import RecursiveCharacterTextSplitter
29
-
30
- import os
31
  import requests
32
  import zipfile
33
-
34
  def download_and_unzip(url, output_dir):
35
  response = requests.get(url)
36
  zip_file_path = os.path.basename(url)
@@ -40,11 +27,9 @@ def download_and_unzip(url, output_dir):
40
  zip_ref.extractall(output_dir)
41
  os.remove(zip_file_path)
42
 
43
- url = "https://minio.carlboettiger.info/public-data/hwc.zip"
44
- output_dir = "hwc"
45
- download_and_unzip(url, "hwc")
46
 
47
  import pathlib
 
48
  @st.cache_data
49
  def pdf_loader(path):
50
  all_documents = []
@@ -55,63 +40,64 @@ def pdf_loader(path):
55
  all_documents.extend(documents)
56
  return all_documents
57
 
 
58
  docs = pdf_loader('hwc/')
59
 
60
 
61
-
62
- # Set up the language model
63
- from langchain_openai import ChatOpenAI
64
- llm = ChatOpenAI(model = "llama3", api_key = api_key, base_url = "https://llm.nrp-nautilus.io", temperature=0)
65
- ## Cirrus instead:
66
-
67
-
68
 
69
 
70
  # Build a retrival agent
71
- from langchain_core.vectorstores import InMemoryVectorStore
72
  from langchain_text_splitters import RecursiveCharacterTextSplitter
73
-
74
-
75
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=300)
76
  splits = text_splitter.split_documents(docs)
77
 
 
78
  @st.cache_resource
79
  def vector_store(_splits):
80
- embedding = OpenAIEmbeddings(
81
- model = "cirrus",
82
- api_key = cirrus_key,
83
- base_url = "https://llm.cirrus.carlboettiger.info/v1",
84
- )
85
  vectorstore = InMemoryVectorStore.from_documents(documents=_splits, embedding=embedding)
86
  retriever = vectorstore.as_retriever()
87
  return retriever
88
 
 
89
  retriever = vector_store(splits)
90
 
91
- from langchain.chains import create_retrieval_chain
92
- from langchain.chains.combine_documents import create_stuff_documents_chain
93
- from langchain_core.prompts import ChatPromptTemplate
 
94
  system_prompt = (
95
  "You are an assistant for question-answering tasks. "
96
  "Use the following scientific articles as the retrieved context to answer "
97
- "the question. If you don't know the answer, say that you "
98
- "don't know. Use up to five sentences maximum and keep the "
 
 
99
  "answer concise."
100
  "\n\n"
101
  "{context}"
102
  )
 
 
103
  prompt = ChatPromptTemplate.from_messages(
104
  [
105
  ("system", system_prompt),
106
  ("human", "{input}"),
107
  ]
108
  )
 
109
  question_answer_chain = create_stuff_documents_chain(llm, prompt)
 
110
  rag_chain = create_retrieval_chain(retriever, question_answer_chain)
111
 
112
 
113
- # Place agent inside a streamlit application:
114
 
 
115
  if prompt := st.chat_input("What are the most cost-effective prevention methods for elephants raiding my crops?"):
116
  with st.chat_message("user"):
117
  st.markdown(prompt)
@@ -121,6 +107,7 @@ if prompt := st.chat_input("What are the most cost-effective prevention methods
121
  st.write(results['answer'])
122
 
123
  with st.expander("See context matched"):
 
124
  st.write(results['context'])
125
 
126
 
 
1
  import streamlit as st
 
2
 
3
  ## dockerized streamlit app wants to read from os.getenv(), otherwise use st.secrets
4
  import os
 
16
  (Demo will take a while to load first while processing all data! Will be pre-processed in future...)
17
  '''
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  import requests
20
  import zipfile
 
21
  def download_and_unzip(url, output_dir):
22
  response = requests.get(url)
23
  zip_file_path = os.path.basename(url)
 
27
  zip_ref.extractall(output_dir)
28
  os.remove(zip_file_path)
29
 
 
 
 
30
 
31
  import pathlib
32
+ from langchain_community.document_loaders import PyPDFLoader
33
  @st.cache_data
34
  def pdf_loader(path):
35
  all_documents = []
 
40
  all_documents.extend(documents)
41
  return all_documents
42
 
43
+ download_and_unzip("https://minio.carlboettiger.info/public-data/hwc.zip", "hwc")
44
  docs = pdf_loader('hwc/')
45
 
46
 
47
+ from langchain_openai import OpenAIEmbeddings
48
+ embedding = OpenAIEmbeddings(
49
+ model = "cirrus",
50
+ api_key = cirrus_key,
51
+ base_url = "https://llm.cirrus.carlboettiger.info/v1",
52
+ )
 
53
 
54
 
55
  # Build a retrival agent
 
56
  from langchain_text_splitters import RecursiveCharacterTextSplitter
 
 
57
  text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=300)
58
  splits = text_splitter.split_documents(docs)
59
 
60
+ from langchain_core.vectorstores import InMemoryVectorStore
61
  @st.cache_resource
62
  def vector_store(_splits):
 
 
 
 
 
63
  vectorstore = InMemoryVectorStore.from_documents(documents=_splits, embedding=embedding)
64
  retriever = vectorstore.as_retriever()
65
  return retriever
66
 
67
+ # here we go, slow part:
68
  retriever = vector_store(splits)
69
 
70
+ # Set up the language model
71
+ from langchain_openai import ChatOpenAI
72
+ llm = ChatOpenAI(model = "llama3", api_key = api_key, base_url = "https://llm.nrp-nautilus.io", temperature=0)
73
+ ## Cirrus instead:
74
  system_prompt = (
75
  "You are an assistant for question-answering tasks. "
76
  "Use the following scientific articles as the retrieved context to answer "
77
+ "the question. Appropriately cite the articles from the context on which your answer is based. "
78
+ "Do not attempt to cite articles that are not in the context."
79
+ "If you don't know the answer, say that you don't know."
80
+ "Use up to five sentences maximum and keep the "
81
  "answer concise."
82
  "\n\n"
83
  "{context}"
84
  )
85
+
86
+ from langchain_core.prompts import ChatPromptTemplate
87
  prompt = ChatPromptTemplate.from_messages(
88
  [
89
  ("system", system_prompt),
90
  ("human", "{input}"),
91
  ]
92
  )
93
+ from langchain.chains.combine_documents import create_stuff_documents_chain
94
  question_answer_chain = create_stuff_documents_chain(llm, prompt)
95
+ from langchain.chains import create_retrieval_chain
96
  rag_chain = create_retrieval_chain(retriever, question_answer_chain)
97
 
98
 
 
99
 
100
+ # Place agent inside a streamlit application:
101
  if prompt := st.chat_input("What are the most cost-effective prevention methods for elephants raiding my crops?"):
102
  with st.chat_message("user"):
103
  st.markdown(prompt)
 
107
  st.write(results['answer'])
108
 
109
  with st.expander("See context matched"):
110
+ # FIXME parse results dict and display in pretty format
111
  st.write(results['context'])
112
 
113
 
vllm-tutorial.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 10,
6
  "id": "405bc169-e0b7-48e6-84b8-4e4a791cf61a",
7
  "metadata": {
8
  "scrolled": true
@@ -12,60 +12,62 @@
12
  "name": "stdout",
13
  "output_type": "stream",
14
  "text": [
15
- "INFO 06-07 04:15:58 [__init__.py:243] Automatically detected platform cuda.\n",
16
- "INFO 06-07 04:16:02 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
17
- "INFO 06-07 04:16:02 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
18
- "INFO 06-07 04:16:02 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
19
- "INFO 06-07 04:16:03 [api_server.py:1289] vLLM API server version 0.9.0.1\n",
20
- "INFO 06-07 04:16:03 [cli_args.py:300] non-default args: {'host': '0.0.0.0', 'task': 'embed', 'trust_remote_code': True, 'enforce_eager': True, 'tensor_parallel_size': 2, 'gpu_memory_utilization': 0.4}\n",
21
- "WARNING 06-07 04:16:14 [config.py:907] awq quantization is not fully optimized yet. The speed can be slower than non-quantized models.\n",
22
- "WARNING 06-07 04:16:14 [arg_utils.py:1583] Compute Capability < 8.0 is not supported by the V1 Engine. Falling back to V0. \n",
23
- "WARNING 06-07 04:16:14 [arg_utils.py:1431] The model has a long context length (40960). This may causeOOM during the initial memory profiling phase, or result in low performance due to small KV cache size. Consider setting --max-model-len to a smaller value.\n",
24
- "INFO 06-07 04:16:14 [config.py:1875] Defaulting to use mp for distributed inference\n",
25
- "WARNING 06-07 04:16:14 [cuda.py:87] To see benefits of async output processing, enable CUDA graph. Since, enforce-eager is enabled, async output processor cannot be used\n",
26
- "INFO 06-07 04:16:14 [api_server.py:257] Started engine process with PID 13896\n",
27
- "INFO 06-07 04:16:18 [__init__.py:243] Automatically detected platform cuda.\n",
28
- "INFO 06-07 04:16:21 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
29
- "INFO 06-07 04:16:21 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
30
- "INFO 06-07 04:16:21 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
31
- "INFO 06-07 04:16:21 [llm_engine.py:230] Initializing a V0 LLM engine (v0.9.0.1) with config: model='Qwen/Qwen3-32B-AWQ', speculative_config=None, tokenizer='Qwen/Qwen3-32B-AWQ', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, override_neuron_config={}, tokenizer_revision=None, trust_remote_code=True, dtype=torch.float16, max_seq_len=40960, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=2, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=awq, enforce_eager=True, kv_cache_dtype=auto, device_config=cuda, decoding_config=DecodingConfig(backend='auto', disable_fallback=False, disable_any_whitespace=False, disable_additional_properties=False, reasoning_backend=''), observability_config=ObservabilityConfig(show_hidden_metrics_for_version=None, otlp_traces_endpoint=None, collect_detailed_traces=None), seed=0, served_model_name=Qwen/Qwen3-32B-AWQ, num_scheduler_steps=1, multi_step_stream_outputs=True, enable_prefix_caching=None, chunked_prefill_enabled=False, use_async_output_proc=False, pooler_config=PoolerConfig(pooling_type=None, normalize=None, softmax=None, step_tag_id=None, returned_token_ids=None), compilation_config={\"compile_sizes\": [], \"inductor_compile_config\": {\"enable_auto_functionalized_v2\": false}, \"cudagraph_capture_sizes\": [], \"max_capture_size\": 0}, use_cached_outputs=True, \n",
32
- "WARNING 06-07 04:16:22 [multiproc_worker_utils.py:306] Reducing Torch parallelism from 64 threads to 1 to avoid unnecessary CPU contention. Set OMP_NUM_THREADS in the external environment to tune this value as needed.\n",
33
- "INFO 06-07 04:16:22 [cuda.py:240] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.\n",
34
- "INFO 06-07 04:16:22 [cuda.py:289] Using XFormers backend.\n",
35
- "INFO 06-07 04:16:27 [__init__.py:243] Automatically detected platform cuda.\n",
36
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [multiproc_worker_utils.py:225] Worker ready; awaiting tasks\n",
37
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
38
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
39
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
40
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [cuda.py:240] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.\n",
41
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:30 [cuda.py:289] Using XFormers backend.\n",
42
- "INFO 06-07 04:16:31 [utils.py:1077] Found nccl from library libnccl.so.2\n",
43
- "INFO 06-07 04:16:31 [pynccl.py:69] vLLM is using nccl==2.26.2\n",
44
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:31 [utils.py:1077] Found nccl from library libnccl.so.2\n",
45
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:31 [pynccl.py:69] vLLM is using nccl==2.26.2\n",
46
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:31 [custom_all_reduce_utils.py:245] reading GPU P2P access cache from /home/jovyan/.cache/vllm/gpu_p2p_access_cache_for_0,1.json\n",
47
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m WARNING 06-07 04:16:31 [custom_all_reduce.py:146] Custom allreduce is disabled because your platform lacks GPU P2P capability or P2P test failed. To silence this warning, specify disable_custom_all_reduce=True explicitly.\n",
48
- "INFO 06-07 04:16:31 [custom_all_reduce_utils.py:245] reading GPU P2P access cache from /home/jovyan/.cache/vllm/gpu_p2p_access_cache_for_0,1.json\n",
49
- "WARNING 06-07 04:16:31 [custom_all_reduce.py:146] Custom allreduce is disabled because your platform lacks GPU P2P capability or P2P test failed. To silence this warning, specify disable_custom_all_reduce=True explicitly.\n",
50
- "INFO 06-07 04:16:31 [shm_broadcast.py:250] vLLM message queue communication handle: Handle(local_reader_ranks=[1], buffer_handle=(1, 4194304, 6, 'psm_8808788c'), local_subscribe_addr='ipc:///tmp/f2f3507a-b619-4382-897c-4059a5a27e80', remote_subscribe_addr=None, remote_addr_ipv6=False)\n",
51
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:31 [parallel_state.py:1064] rank 1 in world size 2 is assigned as DP rank 0, PP rank 0, TP rank 1, EP rank 1\n",
52
- "INFO 06-07 04:16:31 [parallel_state.py:1064] rank 0 in world size 2 is assigned as DP rank 0, PP rank 0, TP rank 0, EP rank 0\n",
53
- "INFO 06-07 04:16:31 [model_runner.py:1170] Starting to load model Qwen/Qwen3-32B-AWQ...\n",
54
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:31 [model_runner.py:1170] Starting to load model Qwen/Qwen3-32B-AWQ...\n",
55
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:16:32 [weight_utils.py:291] Using model weights format ['*.safetensors']\n",
56
- "INFO 06-07 04:16:32 [weight_utils.py:291] Using model weights format ['*.safetensors']\n"
 
 
 
 
57
  ]
58
  },
59
  {
60
  "name": "stderr",
61
  "output_type": "stream",
62
  "text": [
63
- "Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00<?, ?it/s]\n",
64
- "Loading safetensors checkpoint shards: 25% Completed | 1/4 [00:04<00:13, 4.64s/it]\n",
65
- "Loading safetensors checkpoint shards: 50% Completed | 2/4 [00:13<00:13, 6.86s/it]\n",
66
- "Loading safetensors checkpoint shards: 75% Completed | 3/4 [00:21<00:07, 7.69s/it]\n",
67
- "Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:29<00:00, 7.84s/it]\n",
68
- "Loading safetensors checkpoint shards: 100% Completed | 4/4 [00:29<00:00, 7.45s/it]\n",
69
  "\n"
70
  ]
71
  },
@@ -73,44 +75,44 @@
73
  "name": "stdout",
74
  "output_type": "stream",
75
  "text": [
76
- "INFO 06-07 04:17:02 [default_loader.py:280] Loading weights took 29.98 seconds\n",
77
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:17:02 [default_loader.py:280] Loading weights took 30.20 seconds\n",
78
- "INFO 06-07 04:17:02 [model_runner.py:1202] Model loading took 8.3324 GiB and 31.055884 seconds\n",
79
- "\u001b[1;36m(VllmWorkerProcess pid=14061)\u001b[0;0m INFO 06-07 04:17:02 [model_runner.py:1202] Model loading took 8.3324 GiB and 31.096897 seconds\n",
80
- "INFO 06-07 04:17:03 [api_server.py:1336] Starting vLLM API server on http://0.0.0.0:8000\n",
81
- "INFO 06-07 04:17:03 [launcher.py:28] Available routes are:\n",
82
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /openapi.json, Methods: GET, HEAD\n",
83
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /docs, Methods: GET, HEAD\n",
84
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /docs/oauth2-redirect, Methods: GET, HEAD\n",
85
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /redoc, Methods: GET, HEAD\n",
86
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /health, Methods: GET\n",
87
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /load, Methods: GET\n",
88
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /ping, Methods: POST\n",
89
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /ping, Methods: GET\n",
90
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /tokenize, Methods: POST\n",
91
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /detokenize, Methods: POST\n",
92
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/models, Methods: GET\n",
93
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /version, Methods: GET\n",
94
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/chat/completions, Methods: POST\n",
95
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/completions, Methods: POST\n",
96
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/embeddings, Methods: POST\n",
97
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /pooling, Methods: POST\n",
98
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /classify, Methods: POST\n",
99
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /score, Methods: POST\n",
100
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/score, Methods: POST\n",
101
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/audio/transcriptions, Methods: POST\n",
102
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /rerank, Methods: POST\n",
103
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v1/rerank, Methods: POST\n",
104
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /v2/rerank, Methods: POST\n",
105
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /invocations, Methods: POST\n",
106
- "INFO 06-07 04:17:03 [launcher.py:36] Route: /metrics, Methods: GET\n"
107
  ]
108
  },
109
  {
110
  "name": "stderr",
111
  "output_type": "stream",
112
  "text": [
113
- "INFO: Started server process [13556]\n",
114
  "INFO: Waiting for application startup.\n",
115
  "INFO: Application startup complete.\n"
116
  ]
@@ -124,25 +126,27 @@
124
  "\n",
125
  "# Set environment variable we need to support dual-GPU on Cirrus\n",
126
  "os.environ[\"NCCL_P2P_LEVEL\"] = \"NVL\"\n",
 
127
  "\n",
 
128
  "def run_vllm_server():\n",
129
  " subprocess.run([\n",
130
- " \"vllm\", \"serve\", \"Qwen/Qwen3-32B-AWQ\",\n",
131
  " \"--host\", \"0.0.0.0\",\n",
132
  " \"--port\", \"8000\",\n",
133
  " \"--tensor-parallel-size\", \"2\",\n",
134
  " \"--trust-remote-code\",\n",
135
  " \"--gpu-memory-utilization\", \"0.4\",\n",
136
  " \"--enforce-eager\",\n",
137
- " \"--task\", \"embed\"\n",
 
138
  " ])\n",
139
  "\n",
140
  "# Start server in daemon thread\n",
141
  "server_thread = threading.Thread(target=run_vllm_server, daemon=True)\n",
142
  "server_thread.start()\n",
143
  "\n",
144
- "## give server time to start up.\n",
145
- "\n",
146
  "import time\n",
147
  "# Pause execution for 100 seconds\n",
148
  "time.sleep(200)"
@@ -169,10 +173,11 @@
169
  "name": "stdout",
170
  "output_type": "stream",
171
  "text": [
172
- "INFO 06-07 04:02:50 [logger.py:42] Received request embd-32a68fa8f24a4855b090f66f426e61c4-0: prompt: ' product down', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [1985, 1495], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
173
- "INFO 06-07 04:02:50 [engine.py:316] Added request embd-32a68fa8f24a4855b090f66f426e61c4-0.\n",
174
- "INFO 06-07 04:02:52 [metrics.py:486] Avg prompt throughput: 0.2 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n",
175
- "INFO: 127.0.0.1:37090 - \"POST /v1/embeddings HTTP/1.1\" 200 OK\n"
 
176
  ]
177
  }
178
  ],
@@ -181,19 +186,188 @@
181
  "## Connect to the local model\n",
182
  "from langchain_openai import OpenAIEmbeddings\n",
183
  "embedding = OpenAIEmbeddings(\n",
184
- " model = \"Qwen/Qwen3-32B-AWQ\",\n",
185
- " api_key = \"EMPTY\",\n",
186
  " base_url = \"http://localhost:8000/v1\",\n",
187
  ")\n",
188
  "\n",
189
- "## test that we can do embeddings\n",
190
  "from langchain_core.vectorstores import InMemoryVectorStore\n",
191
  "vectorstore = InMemoryVectorStore.from_texts([\"test text\"], embedding=embedding)"
192
  ]
193
  },
194
  {
195
  "cell_type": "code",
196
- "execution_count": 4,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  "id": "95ed10f3-5339-40cd-bf16-b0854f8b4b91",
198
  "metadata": {},
199
  "outputs": [],
@@ -229,13 +403,87 @@
229
  },
230
  {
231
  "cell_type": "code",
232
- "execution_count": 9,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  "id": "c6e99791-8f34-4722-9708-665e409c26bd",
234
  "metadata": {},
235
  "outputs": [],
236
  "source": [
237
  "# Set up the Chat model from one of the NRP models\n",
238
- "\n",
239
  "import os\n",
240
  "api_key = os.getenv(\"OPENAI_API_KEY\")\n",
241
  "\n",
@@ -260,36 +508,7 @@
260
  },
261
  {
262
  "cell_type": "code",
263
- "execution_count": null,
264
- "id": "95d3e9a3-7334-44ba-a4bc-e7bfc4076358",
265
- "metadata": {},
266
- "outputs": [],
267
- "source": [
268
- "# Build a retrival agent\n",
269
- "from langchain_core.vectorstores import InMemoryVectorStore\n",
270
- "from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
271
- "text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)\n",
272
- "splits = text_splitter.split_documents(docs)"
273
- ]
274
- },
275
- {
276
- "cell_type": "code",
277
- "execution_count": null,
278
- "id": "fd8bcc13-d06d-43dd-9e06-4f29da803133",
279
- "metadata": {
280
- "scrolled": true
281
- },
282
- "outputs": [],
283
- "source": [
284
- "# slow part here, runs on remote GPU\n",
285
- "from langchain_core.vectorstores import InMemoryVectorStore\n",
286
- "vectorstore = InMemoryVectorStore.from_documents(documents=splits, embedding=embedding)\n",
287
- "retriever = vectorstore.as_retriever()"
288
- ]
289
- },
290
- {
291
- "cell_type": "code",
292
- "execution_count": null,
293
  "id": "2bf50abf-5ccd-4de5-9fc4-c9043a66a108",
294
  "metadata": {},
295
  "outputs": [],
@@ -301,7 +520,7 @@
301
  " \"You are an assistant for question-answering tasks. \"\n",
302
  " \"Use the following pieces of retrieved context to answer \"\n",
303
  " \"the question. If you don't know the answer, say that you \"\n",
304
- " \"don't know. Use three sentences maximum and keep the \"\n",
305
  " \"answer concise.\"\n",
306
  " \"\\n\\n\"\n",
307
  " \"{context}\"\n",
@@ -385,10 +604,43 @@
385
  },
386
  {
387
  "cell_type": "code",
388
- "execution_count": null,
389
  "id": "ba272b88-1622-4d06-9361-7f1e2ca89e73",
390
  "metadata": {},
391
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  "source": [
393
  "prompt = \"What cattle husbandry strategies might be helpful to prevent conflict if we live in wolf country?\"\n",
394
  "\n",
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "id": "405bc169-e0b7-48e6-84b8-4e4a791cf61a",
7
  "metadata": {
8
  "scrolled": true
 
12
  "name": "stdout",
13
  "output_type": "stream",
14
  "text": [
15
+ "INFO 06-07 22:36:36 [__init__.py:243] Automatically detected platform cuda.\n",
16
+ "INFO 06-07 22:36:40 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
17
+ "INFO 06-07 22:36:40 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
18
+ "INFO 06-07 22:36:40 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
19
+ "INFO 06-07 22:36:41 [api_server.py:1289] vLLM API server version 0.9.0.1\n",
20
+ "INFO 06-07 22:36:41 [cli_args.py:300] non-default args: {'host': '0.0.0.0', 'task': 'embed', 'trust_remote_code': True, 'enforce_eager': True, 'served_model_name': ['local'], 'tensor_parallel_size': 2, 'gpu_memory_utilization': 0.4}\n",
21
+ "WARNING 06-07 22:36:43 [config.py:3096] Your Quadro RTX 8000 device (with compute capability 7.5) doesn't support torch.bfloat16. Falling back to torch.float16 for compatibility.\n",
22
+ "WARNING 06-07 22:36:43 [config.py:3135] Casting torch.bfloat16 to torch.float16.\n",
23
+ "INFO 06-07 22:36:51 [config.py:473] Found sentence-transformers modules configuration.\n",
24
+ "INFO 06-07 22:36:52 [config.py:493] Found pooling configuration.\n",
25
+ "WARNING 06-07 22:36:52 [arg_utils.py:1583] Compute Capability < 8.0 is not supported by the V1 Engine. Falling back to V0. \n",
26
+ "WARNING 06-07 22:36:52 [arg_utils.py:1431] The model has a long context length (40960). This may causeOOM during the initial memory profiling phase, or result in low performance due to small KV cache size. Consider setting --max-model-len to a smaller value.\n",
27
+ "INFO 06-07 22:36:52 [config.py:1875] Defaulting to use mp for distributed inference\n",
28
+ "WARNING 06-07 22:36:52 [cuda.py:87] To see benefits of async output processing, enable CUDA graph. Since, enforce-eager is enabled, async output processor cannot be used\n",
29
+ "INFO 06-07 22:36:52 [api_server.py:257] Started engine process with PID 16420\n",
30
+ "INFO 06-07 22:36:56 [__init__.py:243] Automatically detected platform cuda.\n",
31
+ "INFO 06-07 22:36:59 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
32
+ "INFO 06-07 22:36:59 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
33
+ "INFO 06-07 22:36:59 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
34
+ "INFO 06-07 22:36:59 [llm_engine.py:230] Initializing a V0 LLM engine (v0.9.0.1) with config: model='Qwen/Qwen3-Embedding-4B', speculative_config=None, tokenizer='Qwen/Qwen3-Embedding-4B', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, override_neuron_config={}, tokenizer_revision=None, trust_remote_code=True, dtype=torch.float16, max_seq_len=40960, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=2, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=True, kv_cache_dtype=auto, device_config=cuda, decoding_config=DecodingConfig(backend='auto', disable_fallback=False, disable_any_whitespace=False, disable_additional_properties=False, reasoning_backend=''), observability_config=ObservabilityConfig(show_hidden_metrics_for_version=None, otlp_traces_endpoint=None, collect_detailed_traces=None), seed=0, served_model_name=local, num_scheduler_steps=1, multi_step_stream_outputs=True, enable_prefix_caching=None, chunked_prefill_enabled=False, use_async_output_proc=False, pooler_config=PoolerConfig(pooling_type='LAST', normalize=True, softmax=None, step_tag_id=None, returned_token_ids=None), compilation_config={\"compile_sizes\": [], \"inductor_compile_config\": {\"enable_auto_functionalized_v2\": false}, \"cudagraph_capture_sizes\": [], \"max_capture_size\": 0}, use_cached_outputs=True, \n",
35
+ "WARNING 06-07 22:37:00 [multiproc_worker_utils.py:306] Reducing Torch parallelism from 64 threads to 1 to avoid unnecessary CPU contention. Set OMP_NUM_THREADS in the external environment to tune this value as needed.\n",
36
+ "INFO 06-07 22:37:00 [cuda.py:240] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.\n",
37
+ "INFO 06-07 22:37:00 [cuda.py:289] Using XFormers backend.\n",
38
+ "INFO 06-07 22:37:04 [__init__.py:243] Automatically detected platform cuda.\n",
39
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [multiproc_worker_utils.py:225] Worker ready; awaiting tasks\n",
40
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [__init__.py:31] Available plugins for group vllm.general_plugins:\n",
41
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [__init__.py:33] - lora_filesystem_resolver -> vllm.plugins.lora_resolvers.filesystem_resolver:register_filesystem_resolver\n",
42
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [__init__.py:36] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.\n",
43
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [cuda.py:240] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.\n",
44
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:07 [cuda.py:289] Using XFormers backend.\n",
45
+ "INFO 06-07 22:37:08 [utils.py:1077] Found nccl from library libnccl.so.2\n",
46
+ "INFO 06-07 22:37:08 [pynccl.py:69] vLLM is using nccl==2.26.2\n",
47
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:08 [utils.py:1077] Found nccl from library libnccl.so.2\n",
48
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:08 [pynccl.py:69] vLLM is using nccl==2.26.2\n",
49
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:09 [custom_all_reduce_utils.py:245] reading GPU P2P access cache from /home/jovyan/.cache/vllm/gpu_p2p_access_cache_for_0,1.json\n",
50
+ "INFO 06-07 22:37:09 [custom_all_reduce_utils.py:245] reading GPU P2P access cache from /home/jovyan/.cache/vllm/gpu_p2p_access_cache_for_0,1.json\n",
51
+ "WARNING 06-07 22:37:09 [custom_all_reduce.py:146] Custom allreduce is disabled because your platform lacks GPU P2P capability or P2P test failed. To silence this warning, specify disable_custom_all_reduce=True explicitly.\n",
52
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m WARNING 06-07 22:37:09 [custom_all_reduce.py:146] Custom allreduce is disabled because your platform lacks GPU P2P capability or P2P test failed. To silence this warning, specify disable_custom_all_reduce=True explicitly.\n",
53
+ "INFO 06-07 22:37:09 [shm_broadcast.py:250] vLLM message queue communication handle: Handle(local_reader_ranks=[1], buffer_handle=(1, 4194304, 6, 'psm_f9ac8311'), local_subscribe_addr='ipc:///tmp/718ad6af-61c7-4d9f-8044-b415ab240a60', remote_subscribe_addr=None, remote_addr_ipv6=False)\n",
54
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:09 [parallel_state.py:1064] rank 1 in world size 2 is assigned as DP rank 0, PP rank 0, TP rank 1, EP rank 1\n",
55
+ "INFO 06-07 22:37:09 [parallel_state.py:1064] rank 0 in world size 2 is assigned as DP rank 0, PP rank 0, TP rank 0, EP rank 0\n",
56
+ "INFO 06-07 22:37:09 [model_runner.py:1170] Starting to load model Qwen/Qwen3-Embedding-4B...\n",
57
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:09 [model_runner.py:1170] Starting to load model Qwen/Qwen3-Embedding-4B...\n",
58
+ "INFO 06-07 22:37:09 [weight_utils.py:291] Using model weights format ['*.safetensors']\n",
59
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:37:09 [weight_utils.py:291] Using model weights format ['*.safetensors']\n",
60
+ "INFO 06-07 22:38:15 [weight_utils.py:307] Time spent downloading weights for Qwen/Qwen3-Embedding-4B: 65.320092 seconds\n"
61
  ]
62
  },
63
  {
64
  "name": "stderr",
65
  "output_type": "stream",
66
  "text": [
67
+ "Loading safetensors checkpoint shards: 0% Completed | 0/2 [00:00<?, ?it/s]\n",
68
+ "Loading safetensors checkpoint shards: 50% Completed | 1/2 [00:02<00:02, 2.96s/it]\n",
69
+ "Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:09<00:00, 4.92s/it]\n",
70
+ "Loading safetensors checkpoint shards: 100% Completed | 2/2 [00:09<00:00, 4.63s/it]\n",
 
 
71
  "\n"
72
  ]
73
  },
 
75
  "name": "stdout",
76
  "output_type": "stream",
77
  "text": [
78
+ "INFO 06-07 22:38:24 [default_loader.py:280] Loading weights took 9.43 seconds\n",
79
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:38:24 [default_loader.py:280] Loading weights took 9.14 seconds\n",
80
+ "INFO 06-07 22:38:24 [model_runner.py:1202] Model loading took 3.8162 GiB and 75.582441 seconds\n",
81
+ "\u001b[1;36m(VllmWorkerProcess pid=16602)\u001b[0;0m INFO 06-07 22:38:25 [model_runner.py:1202] Model loading took 3.8162 GiB and 75.610664 seconds\n",
82
+ "INFO 06-07 22:38:25 [api_server.py:1336] Starting vLLM API server on http://0.0.0.0:8000\n",
83
+ "INFO 06-07 22:38:25 [launcher.py:28] Available routes are:\n",
84
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /openapi.json, Methods: GET, HEAD\n",
85
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /docs, Methods: GET, HEAD\n",
86
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /docs/oauth2-redirect, Methods: GET, HEAD\n",
87
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /redoc, Methods: GET, HEAD\n",
88
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /health, Methods: GET\n",
89
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /load, Methods: GET\n",
90
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /ping, Methods: POST\n",
91
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /ping, Methods: GET\n",
92
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /tokenize, Methods: POST\n",
93
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /detokenize, Methods: POST\n",
94
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/models, Methods: GET\n",
95
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /version, Methods: GET\n",
96
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/chat/completions, Methods: POST\n",
97
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/completions, Methods: POST\n",
98
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/embeddings, Methods: POST\n",
99
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /pooling, Methods: POST\n",
100
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /classify, Methods: POST\n",
101
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /score, Methods: POST\n",
102
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/score, Methods: POST\n",
103
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/audio/transcriptions, Methods: POST\n",
104
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /rerank, Methods: POST\n",
105
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v1/rerank, Methods: POST\n",
106
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /v2/rerank, Methods: POST\n",
107
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /invocations, Methods: POST\n",
108
+ "INFO 06-07 22:38:25 [launcher.py:36] Route: /metrics, Methods: GET\n"
109
  ]
110
  },
111
  {
112
  "name": "stderr",
113
  "output_type": "stream",
114
  "text": [
115
+ "INFO: Started server process [16093]\n",
116
  "INFO: Waiting for application startup.\n",
117
  "INFO: Application startup complete.\n"
118
  ]
 
126
  "\n",
127
  "# Set environment variable we need to support dual-GPU on Cirrus\n",
128
  "os.environ[\"NCCL_P2P_LEVEL\"] = \"NVL\"\n",
129
+ "os.environ[\"VLLM_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\") # set same key for simplicity\n",
130
  "\n",
131
+ "# https://huggingface.co/spaces/mteb/leaderboard \n",
132
  "def run_vllm_server():\n",
133
  " subprocess.run([\n",
134
+ " \"vllm\", \"serve\", \"Qwen/Qwen3-Embedding-4B\",\n",
135
  " \"--host\", \"0.0.0.0\",\n",
136
  " \"--port\", \"8000\",\n",
137
  " \"--tensor-parallel-size\", \"2\",\n",
138
  " \"--trust-remote-code\",\n",
139
  " \"--gpu-memory-utilization\", \"0.4\",\n",
140
  " \"--enforce-eager\",\n",
141
+ " \"--served-model-name\", \"local\",\n",
142
+ " \"--task\", \"embed\" # Run in embed mode! (default is 'generate')\n",
143
  " ])\n",
144
  "\n",
145
  "# Start server in daemon thread\n",
146
  "server_thread = threading.Thread(target=run_vllm_server, daemon=True)\n",
147
  "server_thread.start()\n",
148
  "\n",
149
+ "## give server time to start up:\n",
 
150
  "import time\n",
151
  "# Pause execution for 100 seconds\n",
152
  "time.sleep(200)"
 
173
  "name": "stdout",
174
  "output_type": "stream",
175
  "text": [
176
+ "INFO 06-07 22:39:51 [logger.py:42] Received request embd-9059fd2aadf84d8288c45ca3ecc8cd3c-0: prompt: ' product down', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [1985, 1495], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
177
+ "INFO 06-07 22:39:51 [engine.py:316] Added request embd-9059fd2aadf84d8288c45ca3ecc8cd3c-0.\n",
178
+ "INFO 06-07 22:39:53 [metrics.py:486] Avg prompt throughput: 0.2 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n",
179
+ "INFO: 127.0.0.1:36040 - \"POST /v1/embeddings HTTP/1.1\" 200 OK\n",
180
+ "INFO 06-07 22:40:03 [metrics.py:486] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n"
181
  ]
182
  }
183
  ],
 
186
  "## Connect to the local model\n",
187
  "from langchain_openai import OpenAIEmbeddings\n",
188
  "embedding = OpenAIEmbeddings(\n",
189
+ " model = \"local\", ## served model name\n",
190
+ " api_key = os.getenv(\"OPENAI_API_KEY\"),\n",
191
  " base_url = \"http://localhost:8000/v1\",\n",
192
  ")\n",
193
  "\n",
194
+ "## test that the model can do embeddings\n",
195
  "from langchain_core.vectorstores import InMemoryVectorStore\n",
196
  "vectorstore = InMemoryVectorStore.from_texts([\"test text\"], embedding=embedding)"
197
  ]
198
  },
199
  {
200
  "cell_type": "code",
201
+ "execution_count": 22,
202
+ "id": "6181a644-e419-4986-a900-44f1d569d244",
203
+ "metadata": {},
204
+ "outputs": [
205
+ {
206
+ "name": "stdout",
207
+ "output_type": "stream",
208
+ "text": [
209
+ "INFO 06-07 23:16:55 [logger.py:42] Received request embd-60cc555da14743da90337ba88edfe7cf-0: prompt: ' Stainless\">\\r\\n', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [32490, 4424], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
210
+ "INFO 06-07 23:16:55 [engine.py:316] Added request embd-60cc555da14743da90337ba88edfe7cf-0.\n",
211
+ "INFO: 127.0.0.1:53594 - \"POST /v1/embeddings HTTP/1.1\" 200 OK\n",
212
+ "INFO 06-07 23:17:05 [metrics.py:486] Avg prompt throughput: 0.1 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n",
213
+ "INFO 06-07 23:17:15 [metrics.py:486] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n"
214
+ ]
215
+ }
216
+ ],
217
+ "source": [
218
+ "from langchain_qdrant import QdrantVectorStore\n",
219
+ "from qdrant_client import QdrantClient\n",
220
+ "from qdrant_client.http.models import Distance, VectorParams\n",
221
+ "\n",
222
+ "client = QdrantClient(path = \"hwc_qdrant.db\")\n",
223
+ "\n",
224
+ "client.create_collection(\n",
225
+ " collection_name=\"demo_collection\",\n",
226
+ " vectors_config=VectorParams(size=2560, distance=Distance.COSINE),\n",
227
+ ")\n",
228
+ "\n",
229
+ "vector_store = QdrantVectorStore(\n",
230
+ " client=client,\n",
231
+ " collection_name=\"demo_collection\",\n",
232
+ " embedding=embedding\n",
233
+ ")"
234
+ ]
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "execution_count": 28,
239
+ "id": "ec8d7936-d6b9-4487-9146-c42f855523ec",
240
+ "metadata": {},
241
+ "outputs": [
242
+ {
243
+ "name": "stdout",
244
+ "output_type": "stream",
245
+ "text": [
246
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-0: prompt: 'Iys landscape SL defends and-fired Philadelphia for Utils wh whose.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [40, 1047, 18414, 16797, 80960, 323, 71578, 19335, 369, 17954, 420, 6693, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
247
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-1: prompt: 'eg observ.price for guitar is=! andshional,iz aik of deep(long\\\\Category.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [791, 9282, 18057, 369, 16986, 374, 74649, 323, 927, 3914, 11, 449, 264, 1579, 315, 220, 5538, 12628, 69823, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
248
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-2: prompt: '.setPropertyata dram j.Iiz��shareine *) eachessso!', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [31233, 459, 13548, 502, 2447, 449, 23272, 19368, 482, 2586, 1817, 433, 704, 0], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
249
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-3: prompt: ' Wasook.offset_T the means());\\r\\n and.after $1 +\\n in Alex.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [14804, 1941, 14760, 1139, 279, 3363, 6201, 323, 40606, 400, 16, 3610, 304, 8515, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
250
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-4: prompt: ' Traffic! });\\n\\nthisata station=[. Iprra games to================ess ed.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [36981, 0, 3011, 574, 459, 8056, 5818, 13, 358, 649, 956, 3868, 311, 1518, 433, 1578, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
251
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-5: prompt: '.Control the jPairutable theBe?\\t\\t\\t\\n whReg to (!so.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [3957, 279, 502, 12443, 5922, 279, 3430, 30, 4557, 420, 3477, 311, 1505, 704, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
252
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-6: prompt: 'eg between ==== Marine City in the actionutil][.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [791, 1948, 220, 605, 22963, 4311, 304, 279, 1917, 1314, 1457, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
253
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-7: prompt: ' parad Bad is theideo JavaScript for(key modelRO,ault-group Russian!', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [27317, 11461, 374, 279, 1888, 12914, 369, 4857, 1614, 1285, 11, 945, 4351, 8522, 0], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
254
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-8: prompt: 'eg sysyear is_h ehAGE having.io toReceiveMemoryWarning of a strangers.', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [791, 5708, 3157, 374, 1523, 220, 2636, 3585, 3432, 4245, 311, 24087, 315, 264, 39621, 13], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
255
+ "INFO 06-07 23:19:58 [logger.py:42] Received request embd-d18cf8a824104f36a07c970cfa3e999f-9: prompt: 'Iull a éSec Irefoute to �Touchacency', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [40, 617, 264, 3958, 8430, 358, 1097, 2133, 311, 636, 11309, 40624], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
256
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-0.\n",
257
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-1.\n",
258
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-2.\n",
259
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-3.\n",
260
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-4.\n",
261
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-5.\n",
262
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-6.\n",
263
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-7.\n",
264
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-8.\n",
265
+ "INFO 06-07 23:19:58 [engine.py:316] Added request embd-d18cf8a824104f36a07c970cfa3e999f-9.\n",
266
+ "INFO: 127.0.0.1:35840 - \"POST /v1/embeddings HTTP/1.1\" 200 OK\n"
267
+ ]
268
+ },
269
+ {
270
+ "data": {
271
+ "text/plain": [
272
+ "['878ac59d-e276-4d29-b715-6b20cd0f76f8',\n",
273
+ " '5e5c960e-7c02-446d-9ad4-ca930ec3b57a',\n",
274
+ " '8f478874-a730-4e19-b5f2-ef3caeb96a9d',\n",
275
+ " 'ed8dd908-a4da-4b20-b3d3-b2778846298d',\n",
276
+ " 'cc487e15-f7f3-46b6-a0a4-d0be9955cdaa',\n",
277
+ " '5f380da0-9b78-4051-beea-6aa98421df33',\n",
278
+ " 'd5fa20d1-cc94-4613-ac64-b5ba3830589c',\n",
279
+ " 'cb0cbe18-5118-45f6-ae9c-1452b43cb92e',\n",
280
+ " '15181e21-fa5d-45d0-b97b-3e206d671101',\n",
281
+ " '1e769b7d-d327-465e-9b5b-3274b159ede3']"
282
+ ]
283
+ },
284
+ "execution_count": 28,
285
+ "metadata": {},
286
+ "output_type": "execute_result"
287
+ },
288
+ {
289
+ "name": "stdout",
290
+ "output_type": "stream",
291
+ "text": [
292
+ "INFO 06-07 23:20:08 [metrics.py:486] Avg prompt throughput: 12.1 tokens/s, Avg generation throughput: 0.8 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n",
293
+ "INFO 06-07 23:20:19 [metrics.py:486] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n"
294
+ ]
295
+ }
296
+ ],
297
+ "source": [
298
+ "from uuid import uuid4\n",
299
+ "\n",
300
+ "from langchain_core.documents import Document\n",
301
+ "\n",
302
+ "document_1 = Document(\n",
303
+ " page_content=\"I had chocolate chip pancakes and scrambled eggs for breakfast this morning.\",\n",
304
+ " metadata={\"source\": \"tweet\"},\n",
305
+ ")\n",
306
+ "\n",
307
+ "document_2 = Document(\n",
308
+ " page_content=\"The weather forecast for tomorrow is cloudy and overcast, with a high of 62 degrees Fahrenheit.\",\n",
309
+ " metadata={\"source\": \"news\"},\n",
310
+ ")\n",
311
+ "\n",
312
+ "document_3 = Document(\n",
313
+ " page_content=\"Building an exciting new project with LangChain - come check it out!\",\n",
314
+ " metadata={\"source\": \"tweet\"},\n",
315
+ ")\n",
316
+ "\n",
317
+ "document_4 = Document(\n",
318
+ " page_content=\"Robbers broke into the city bank and stole $1 million in cash.\",\n",
319
+ " metadata={\"source\": \"news\"},\n",
320
+ ")\n",
321
+ "\n",
322
+ "document_5 = Document(\n",
323
+ " page_content=\"Wow! That was an amazing movie. I can't wait to see it again.\",\n",
324
+ " metadata={\"source\": \"tweet\"},\n",
325
+ ")\n",
326
+ "\n",
327
+ "document_6 = Document(\n",
328
+ " page_content=\"Is the new iPhone worth the price? Read this review to find out.\",\n",
329
+ " metadata={\"source\": \"website\"},\n",
330
+ ")\n",
331
+ "\n",
332
+ "document_7 = Document(\n",
333
+ " page_content=\"The top 10 soccer players in the world right now.\",\n",
334
+ " metadata={\"source\": \"website\"},\n",
335
+ ")\n",
336
+ "\n",
337
+ "document_8 = Document(\n",
338
+ " page_content=\"LangGraph is the best framework for building stateful, agentic applications!\",\n",
339
+ " metadata={\"source\": \"tweet\"},\n",
340
+ ")\n",
341
+ "\n",
342
+ "document_9 = Document(\n",
343
+ " page_content=\"The stock market is down 500 points today due to fears of a recession.\",\n",
344
+ " metadata={\"source\": \"news\"},\n",
345
+ ")\n",
346
+ "\n",
347
+ "document_10 = Document(\n",
348
+ " page_content=\"I have a bad feeling I am going to get deleted :(\",\n",
349
+ " metadata={\"source\": \"tweet\"},\n",
350
+ ")\n",
351
+ "\n",
352
+ "documents = [\n",
353
+ " document_1,\n",
354
+ " document_2,\n",
355
+ " document_3,\n",
356
+ " document_4,\n",
357
+ " document_5,\n",
358
+ " document_6,\n",
359
+ " document_7,\n",
360
+ " document_8,\n",
361
+ " document_9,\n",
362
+ " document_10,\n",
363
+ "]\n",
364
+ "uuids = [str(uuid4()) for _ in range(len(documents))]\n",
365
+ "vector_store.add_documents(documents=documents, ids=uuids)"
366
+ ]
367
+ },
368
+ {
369
+ "cell_type": "code",
370
+ "execution_count": 3,
371
  "id": "95ed10f3-5339-40cd-bf16-b0854f8b4b91",
372
  "metadata": {},
373
  "outputs": [],
 
403
  },
404
  {
405
  "cell_type": "code",
406
+ "execution_count": 25,
407
+ "id": "95d3e9a3-7334-44ba-a4bc-e7bfc4076358",
408
+ "metadata": {},
409
+ "outputs": [],
410
+ "source": [
411
+ "# Build a retrival agent\n",
412
+ "from langchain_core.vectorstores import InMemoryVectorStore\n",
413
+ "from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
414
+ "text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)\n",
415
+ "splits = text_splitter.split_documents(docs)"
416
+ ]
417
+ },
418
+ {
419
+ "cell_type": "code",
420
+ "execution_count": 27,
421
+ "id": "fd8bcc13-d06d-43dd-9e06-4f29da803133",
422
+ "metadata": {
423
+ "scrolled": true
424
+ },
425
+ "outputs": [
426
+ {
427
+ "ename": "ResponseHandlingException",
428
+ "evalue": "[Errno 111] Connection refused",
429
+ "output_type": "error",
430
+ "traceback": [
431
+ "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
432
+ "\u001b[31mConnectError\u001b[39m Traceback (most recent call last)",
433
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_transports/default.py:101\u001b[39m, in \u001b[36mmap_httpcore_exceptions\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 100\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m101\u001b[39m \u001b[38;5;28;01myield\u001b[39;00m\n\u001b[32m 102\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n",
434
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_transports/default.py:250\u001b[39m, in \u001b[36mHTTPTransport.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 249\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m map_httpcore_exceptions():\n\u001b[32m--> \u001b[39m\u001b[32m250\u001b[39m resp = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_pool\u001b[49m\u001b[43m.\u001b[49m\u001b[43mhandle_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreq\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 252\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(resp.stream, typing.Iterable)\n",
435
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:256\u001b[39m, in \u001b[36mConnectionPool.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 255\u001b[39m \u001b[38;5;28mself\u001b[39m._close_connections(closing)\n\u001b[32m--> \u001b[39m\u001b[32m256\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m exc \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 258\u001b[39m \u001b[38;5;66;03m# Return the response. Note that in this case we still have to manage\u001b[39;00m\n\u001b[32m 259\u001b[39m \u001b[38;5;66;03m# the point at which the response is closed.\u001b[39;00m\n",
436
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py:236\u001b[39m, in \u001b[36mConnectionPool.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 234\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 235\u001b[39m \u001b[38;5;66;03m# Send the request on the assigned connection.\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m236\u001b[39m response = \u001b[43mconnection\u001b[49m\u001b[43m.\u001b[49m\u001b[43mhandle_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 237\u001b[39m \u001b[43m \u001b[49m\u001b[43mpool_request\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\n\u001b[32m 238\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 239\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m ConnectionNotAvailable:\n\u001b[32m 240\u001b[39m \u001b[38;5;66;03m# In some cases a connection may initially be available to\u001b[39;00m\n\u001b[32m 241\u001b[39m \u001b[38;5;66;03m# handle a request, but then become unavailable.\u001b[39;00m\n\u001b[32m 242\u001b[39m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[32m 243\u001b[39m \u001b[38;5;66;03m# In this case we clear the connection and try again.\u001b[39;00m\n",
437
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_sync/connection.py:101\u001b[39m, in \u001b[36mHTTPConnection.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 100\u001b[39m \u001b[38;5;28mself\u001b[39m._connect_failed = \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m101\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m exc\n\u001b[32m 103\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._connection.handle_request(request)\n",
438
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_sync/connection.py:78\u001b[39m, in \u001b[36mHTTPConnection.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 77\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m._connection \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m78\u001b[39m stream = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_connect\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 80\u001b[39m ssl_object = stream.get_extra_info(\u001b[33m\"\u001b[39m\u001b[33mssl_object\u001b[39m\u001b[33m\"\u001b[39m)\n",
439
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_sync/connection.py:124\u001b[39m, in \u001b[36mHTTPConnection._connect\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 123\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m Trace(\u001b[33m\"\u001b[39m\u001b[33mconnect_tcp\u001b[39m\u001b[33m\"\u001b[39m, logger, request, kwargs) \u001b[38;5;28;01mas\u001b[39;00m trace:\n\u001b[32m--> \u001b[39m\u001b[32m124\u001b[39m stream = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_network_backend\u001b[49m\u001b[43m.\u001b[49m\u001b[43mconnect_tcp\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 125\u001b[39m trace.return_value = stream\n",
440
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_backends/sync.py:207\u001b[39m, in \u001b[36mSyncBackend.connect_tcp\u001b[39m\u001b[34m(self, host, port, timeout, local_address, socket_options)\u001b[39m\n\u001b[32m 202\u001b[39m exc_map: ExceptionMapping = {\n\u001b[32m 203\u001b[39m socket.timeout: ConnectTimeout,\n\u001b[32m 204\u001b[39m \u001b[38;5;167;01mOSError\u001b[39;00m: ConnectError,\n\u001b[32m 205\u001b[39m }\n\u001b[32m--> \u001b[39m\u001b[32m207\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m map_exceptions(exc_map):\n\u001b[32m 208\u001b[39m sock = socket.create_connection(\n\u001b[32m 209\u001b[39m address,\n\u001b[32m 210\u001b[39m timeout,\n\u001b[32m 211\u001b[39m source_address=source_address,\n\u001b[32m 212\u001b[39m )\n",
441
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/contextlib.py:158\u001b[39m, in \u001b[36m_GeneratorContextManager.__exit__\u001b[39m\u001b[34m(self, typ, value, traceback)\u001b[39m\n\u001b[32m 157\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m158\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mgen\u001b[49m\u001b[43m.\u001b[49m\u001b[43mthrow\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 159\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[32m 160\u001b[39m \u001b[38;5;66;03m# Suppress StopIteration *unless* it's the same exception that\u001b[39;00m\n\u001b[32m 161\u001b[39m \u001b[38;5;66;03m# was passed to throw(). This prevents a StopIteration\u001b[39;00m\n\u001b[32m 162\u001b[39m \u001b[38;5;66;03m# raised inside the \"with\" statement from being suppressed.\u001b[39;00m\n",
442
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpcore/_exceptions.py:14\u001b[39m, in \u001b[36mmap_exceptions\u001b[39m\u001b[34m(map)\u001b[39m\n\u001b[32m 13\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(exc, from_exc):\n\u001b[32m---> \u001b[39m\u001b[32m14\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m to_exc(exc) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mexc\u001b[39;00m\n\u001b[32m 15\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m\n",
443
+ "\u001b[31mConnectError\u001b[39m: [Errno 111] Connection refused",
444
+ "\nThe above exception was the direct cause of the following exception:\n",
445
+ "\u001b[31mConnectError\u001b[39m Traceback (most recent call last)",
446
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api_client.py:129\u001b[39m, in \u001b[36mApiClient.send_inner\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 128\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m129\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 130\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n",
447
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_client.py:914\u001b[39m, in \u001b[36mClient.send\u001b[39m\u001b[34m(self, request, stream, auth, follow_redirects)\u001b[39m\n\u001b[32m 912\u001b[39m auth = \u001b[38;5;28mself\u001b[39m._build_request_auth(request, auth)\n\u001b[32m--> \u001b[39m\u001b[32m914\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_send_handling_auth\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 915\u001b[39m \u001b[43m \u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 916\u001b[39m \u001b[43m \u001b[49m\u001b[43mauth\u001b[49m\u001b[43m=\u001b[49m\u001b[43mauth\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 917\u001b[39m \u001b[43m \u001b[49m\u001b[43mfollow_redirects\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfollow_redirects\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 918\u001b[39m \u001b[43m \u001b[49m\u001b[43mhistory\u001b[49m\u001b[43m=\u001b[49m\u001b[43m[\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 919\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 920\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
448
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_client.py:942\u001b[39m, in \u001b[36mClient._send_handling_auth\u001b[39m\u001b[34m(self, request, auth, follow_redirects, history)\u001b[39m\n\u001b[32m 941\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m942\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_send_handling_redirects\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 943\u001b[39m \u001b[43m \u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 944\u001b[39m \u001b[43m \u001b[49m\u001b[43mfollow_redirects\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfollow_redirects\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 945\u001b[39m \u001b[43m \u001b[49m\u001b[43mhistory\u001b[49m\u001b[43m=\u001b[49m\u001b[43mhistory\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 946\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 947\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
449
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_client.py:979\u001b[39m, in \u001b[36mClient._send_handling_redirects\u001b[39m\u001b[34m(self, request, follow_redirects, history)\u001b[39m\n\u001b[32m 977\u001b[39m hook(request)\n\u001b[32m--> \u001b[39m\u001b[32m979\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_send_single_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 980\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
450
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_client.py:1014\u001b[39m, in \u001b[36mClient._send_single_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 1013\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m request_context(request=request):\n\u001b[32m-> \u001b[39m\u001b[32m1014\u001b[39m response = \u001b[43mtransport\u001b[49m\u001b[43m.\u001b[49m\u001b[43mhandle_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1016\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(response.stream, SyncByteStream)\n",
451
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_transports/default.py:249\u001b[39m, in \u001b[36mHTTPTransport.handle_request\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 237\u001b[39m req = httpcore.Request(\n\u001b[32m 238\u001b[39m method=request.method,\n\u001b[32m 239\u001b[39m url=httpcore.URL(\n\u001b[32m (...)\u001b[39m\u001b[32m 247\u001b[39m extensions=request.extensions,\n\u001b[32m 248\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m249\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m map_httpcore_exceptions():\n\u001b[32m 250\u001b[39m resp = \u001b[38;5;28mself\u001b[39m._pool.handle_request(req)\n",
452
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/contextlib.py:158\u001b[39m, in \u001b[36m_GeneratorContextManager.__exit__\u001b[39m\u001b[34m(self, typ, value, traceback)\u001b[39m\n\u001b[32m 157\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m158\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mgen\u001b[49m\u001b[43m.\u001b[49m\u001b[43mthrow\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 159\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[32m 160\u001b[39m \u001b[38;5;66;03m# Suppress StopIteration *unless* it's the same exception that\u001b[39;00m\n\u001b[32m 161\u001b[39m \u001b[38;5;66;03m# was passed to throw(). This prevents a StopIteration\u001b[39;00m\n\u001b[32m 162\u001b[39m \u001b[38;5;66;03m# raised inside the \"with\" statement from being suppressed.\u001b[39;00m\n",
453
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/httpx/_transports/default.py:118\u001b[39m, in \u001b[36mmap_httpcore_exceptions\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 117\u001b[39m message = \u001b[38;5;28mstr\u001b[39m(exc)\n\u001b[32m--> \u001b[39m\u001b[32m118\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m mapped_exc(message) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mexc\u001b[39;00m\n",
454
+ "\u001b[31mConnectError\u001b[39m: [Errno 111] Connection refused",
455
+ "\nDuring handling of the above exception, another exception occurred:\n",
456
+ "\u001b[31mResponseHandlingException\u001b[39m Traceback (most recent call last)",
457
+ "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[27]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# slow part here, runs on remote GPU\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m vectorstore = \u001b[43mvector_store\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_documents\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdocuments\u001b[49m\u001b[43m=\u001b[49m\u001b[43msplits\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membedding\u001b[49m\u001b[43m \u001b[49m\u001b[43m=\u001b[49m\u001b[43m \u001b[49m\u001b[43membedding\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 3\u001b[39m retriever = vectorstore.as_retriever()\n",
458
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/langchain_core/vectorstores/base.py:848\u001b[39m, in \u001b[36mVectorStore.from_documents\u001b[39m\u001b[34m(cls, documents, embedding, **kwargs)\u001b[39m\n\u001b[32m 845\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28many\u001b[39m(ids):\n\u001b[32m 846\u001b[39m kwargs[\u001b[33m\"\u001b[39m\u001b[33mids\u001b[39m\u001b[33m\"\u001b[39m] = ids\n\u001b[32m--> \u001b[39m\u001b[32m848\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mfrom_texts\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtexts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43membedding\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadatas\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmetadatas\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
459
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/langchain_qdrant/qdrant.py:343\u001b[39m, in \u001b[36mQdrantVectorStore.from_texts\u001b[39m\u001b[34m(cls, texts, embedding, metadatas, ids, collection_name, location, url, port, grpc_port, prefer_grpc, https, api_key, prefix, timeout, host, path, distance, content_payload_key, metadata_payload_key, vector_name, retrieval_mode, sparse_embedding, sparse_vector_name, collection_create_options, vector_params, sparse_vector_params, batch_size, force_recreate, validate_embeddings, validate_collection_config, **kwargs)\u001b[39m\n\u001b[32m 311\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"Construct an instance of `QdrantVectorStore` from a list of texts.\u001b[39;00m\n\u001b[32m 312\u001b[39m \n\u001b[32m 313\u001b[39m \u001b[33;03mThis is a user-friendly interface that:\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 326\u001b[39m \u001b[33;03m qdrant = Qdrant.from_texts(texts, embeddings, url=\"http://localhost:6333\")\u001b[39;00m\n\u001b[32m 327\u001b[39m \u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 328\u001b[39m client_options = {\n\u001b[32m 329\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mlocation\u001b[39m\u001b[33m\"\u001b[39m: location,\n\u001b[32m 330\u001b[39m \u001b[33m\"\u001b[39m\u001b[33murl\u001b[39m\u001b[33m\"\u001b[39m: url,\n\u001b[32m (...)\u001b[39m\u001b[32m 340\u001b[39m **kwargs,\n\u001b[32m 341\u001b[39m }\n\u001b[32m--> \u001b[39m\u001b[32m343\u001b[39m qdrant = \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mconstruct_instance\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 344\u001b[39m \u001b[43m \u001b[49m\u001b[43membedding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 345\u001b[39m \u001b[43m \u001b[49m\u001b[43mretrieval_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 346\u001b[39m \u001b[43m \u001b[49m\u001b[43msparse_embedding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 347\u001b[39m \u001b[43m \u001b[49m\u001b[43mclient_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 348\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 349\u001b[39m \u001b[43m \u001b[49m\u001b[43mdistance\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 350\u001b[39m \u001b[43m \u001b[49m\u001b[43mcontent_payload_key\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 351\u001b[39m \u001b[43m \u001b[49m\u001b[43mmetadata_payload_key\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 352\u001b[39m \u001b[43m \u001b[49m\u001b[43mvector_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 353\u001b[39m \u001b[43m \u001b[49m\u001b[43msparse_vector_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 354\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_recreate\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 355\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_create_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 356\u001b[39m \u001b[43m \u001b[49m\u001b[43mvector_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 357\u001b[39m \u001b[43m \u001b[49m\u001b[43msparse_vector_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 358\u001b[39m \u001b[43m \u001b[49m\u001b[43mvalidate_embeddings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 359\u001b[39m \u001b[43m \u001b[49m\u001b[43mvalidate_collection_config\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 360\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 361\u001b[39m qdrant.add_texts(texts, metadatas, ids, batch_size)\n\u001b[32m 362\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m qdrant\n",
460
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/langchain_qdrant/qdrant.py:810\u001b[39m, in \u001b[36mQdrantVectorStore.construct_instance\u001b[39m\u001b[34m(cls, embedding, retrieval_mode, sparse_embedding, client_options, collection_name, distance, content_payload_key, metadata_payload_key, vector_name, sparse_vector_name, force_recreate, collection_create_options, vector_params, sparse_vector_params, validate_embeddings, validate_collection_config)\u001b[39m\n\u001b[32m 807\u001b[39m collection_name = collection_name \u001b[38;5;129;01mor\u001b[39;00m uuid.uuid4().hex\n\u001b[32m 808\u001b[39m client = QdrantClient(**client_options)\n\u001b[32m--> \u001b[39m\u001b[32m810\u001b[39m collection_exists = \u001b[43mclient\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcollection_exists\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 812\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m collection_exists \u001b[38;5;129;01mand\u001b[39;00m force_recreate:\n\u001b[32m 813\u001b[39m client.delete_collection(collection_name)\n",
461
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/qdrant_client.py:2240\u001b[39m, in \u001b[36mQdrantClient.collection_exists\u001b[39m\u001b[34m(self, collection_name, **kwargs)\u001b[39m\n\u001b[32m 2230\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"Check whether collection already exists\u001b[39;00m\n\u001b[32m 2231\u001b[39m \n\u001b[32m 2232\u001b[39m \u001b[33;03mArgs:\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 2236\u001b[39m \u001b[33;03m True if collection exists, False if not\u001b[39;00m\n\u001b[32m 2237\u001b[39m \u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 2238\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(kwargs) == \u001b[32m0\u001b[39m, \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mUnknown arguments: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mlist\u001b[39m(kwargs.keys())\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m-> \u001b[39m\u001b[32m2240\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcollection_exists\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
462
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/qdrant_remote.py:2597\u001b[39m, in \u001b[36mQdrantRemote.collection_exists\u001b[39m\u001b[34m(self, collection_name, **kwargs)\u001b[39m\n\u001b[32m 2591\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m._prefer_grpc:\n\u001b[32m 2592\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.grpc_collections.CollectionExists(\n\u001b[32m 2593\u001b[39m grpc.CollectionExistsRequest(collection_name=collection_name),\n\u001b[32m 2594\u001b[39m timeout=\u001b[38;5;28mself\u001b[39m._timeout,\n\u001b[32m 2595\u001b[39m ).result.exists\n\u001b[32m-> \u001b[39m\u001b[32m2597\u001b[39m result: Optional[models.CollectionExistence] = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mhttp\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcollections_api\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcollection_exists\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 2598\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcollection_name\u001b[49m\n\u001b[32m 2599\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m.result\n\u001b[32m 2600\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m result \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[33m\"\u001b[39m\u001b[33mCollection exists returned None\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 2601\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m result.exists\n",
463
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api/collections_api.py:281\u001b[39m, in \u001b[36mSyncCollectionsApi.collection_exists\u001b[39m\u001b[34m(self, collection_name)\u001b[39m\n\u001b[32m 274\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mcollection_exists\u001b[39m(\n\u001b[32m 275\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 276\u001b[39m collection_name: \u001b[38;5;28mstr\u001b[39m,\n\u001b[32m 277\u001b[39m ) -> m.InlineResponse2007:\n\u001b[32m 278\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 279\u001b[39m \u001b[33;03m Returns \\\"true\\\" if the given collection name exists, and \\\"false\\\" otherwise\u001b[39;00m\n\u001b[32m 280\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m281\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_build_for_collection_exists\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 282\u001b[39m \u001b[43m \u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcollection_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 283\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
464
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api/collections_api.py:67\u001b[39m, in \u001b[36m_CollectionsApi._build_for_collection_exists\u001b[39m\u001b[34m(self, collection_name)\u001b[39m\n\u001b[32m 62\u001b[39m path_params = {\n\u001b[32m 63\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mcollection_name\u001b[39m\u001b[33m\"\u001b[39m: \u001b[38;5;28mstr\u001b[39m(collection_name),\n\u001b[32m 64\u001b[39m }\n\u001b[32m 66\u001b[39m headers = {}\n\u001b[32m---> \u001b[39m\u001b[32m67\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mapi_client\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 68\u001b[39m \u001b[43m \u001b[49m\u001b[43mtype_\u001b[49m\u001b[43m=\u001b[49m\u001b[43mm\u001b[49m\u001b[43m.\u001b[49m\u001b[43mInlineResponse2007\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 69\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mGET\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 70\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/collections/\u001b[39;49m\u001b[38;5;132;43;01m{collection_name}\u001b[39;49;00m\u001b[33;43m/exists\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 71\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 72\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 73\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
465
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api_client.py:90\u001b[39m, in \u001b[36mApiClient.request\u001b[39m\u001b[34m(self, type_, method, url, path_params, **kwargs)\u001b[39m\n\u001b[32m 88\u001b[39m kwargs[\u001b[33m\"\u001b[39m\u001b[33mtimeout\u001b[39m\u001b[33m\"\u001b[39m] = \u001b[38;5;28mint\u001b[39m(kwargs[\u001b[33m\"\u001b[39m\u001b[33mparams\u001b[39m\u001b[33m\"\u001b[39m][\u001b[33m\"\u001b[39m\u001b[33mtimeout\u001b[39m\u001b[33m\"\u001b[39m])\n\u001b[32m 89\u001b[39m request = \u001b[38;5;28mself\u001b[39m._client.build_request(method, url, **kwargs)\n\u001b[32m---> \u001b[39m\u001b[32m90\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtype_\u001b[49m\u001b[43m)\u001b[49m\n",
466
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api_client.py:107\u001b[39m, in \u001b[36mApiClient.send\u001b[39m\u001b[34m(self, request, type_)\u001b[39m\n\u001b[32m 106\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34msend\u001b[39m(\u001b[38;5;28mself\u001b[39m, request: Request, type_: Type[T]) -> T:\n\u001b[32m--> \u001b[39m\u001b[32m107\u001b[39m response = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mmiddleware\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43msend_inner\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 109\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m response.status_code == \u001b[32m429\u001b[39m:\n\u001b[32m 110\u001b[39m retry_after_s = response.headers.get(\u001b[33m\"\u001b[39m\u001b[33mRetry-After\u001b[39m\u001b[33m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n",
467
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api_client.py:240\u001b[39m, in \u001b[36mBaseMiddleware.__call__\u001b[39m\u001b[34m(self, request, call_next)\u001b[39m\n\u001b[32m 239\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, request: Request, call_next: Send) -> Response:\n\u001b[32m--> \u001b[39m\u001b[32m240\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcall_next\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m)\u001b[49m\n",
468
+ "\u001b[36mFile \u001b[39m\u001b[32m/opt/conda/lib/python3.12/site-packages/qdrant_client/http/api_client.py:131\u001b[39m, in \u001b[36mApiClient.send_inner\u001b[39m\u001b[34m(self, request)\u001b[39m\n\u001b[32m 129\u001b[39m response = \u001b[38;5;28mself\u001b[39m._client.send(request)\n\u001b[32m 130\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[32m--> \u001b[39m\u001b[32m131\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ResponseHandlingException(e)\n\u001b[32m 132\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m response\n",
469
+ "\u001b[31mResponseHandlingException\u001b[39m: [Errno 111] Connection refused"
470
+ ]
471
+ }
472
+ ],
473
+ "source": [
474
+ "# slow part here, runs on remote GPU\n",
475
+ "vectorstore = vector_store.from_documents(documents=splits, embedding = embedding)\n",
476
+ "retriever = vectorstore.as_retriever()"
477
+ ]
478
+ },
479
+ {
480
+ "cell_type": "code",
481
+ "execution_count": 4,
482
  "id": "c6e99791-8f34-4722-9708-665e409c26bd",
483
  "metadata": {},
484
  "outputs": [],
485
  "source": [
486
  "# Set up the Chat model from one of the NRP models\n",
 
487
  "import os\n",
488
  "api_key = os.getenv(\"OPENAI_API_KEY\")\n",
489
  "\n",
 
508
  },
509
  {
510
  "cell_type": "code",
511
+ "execution_count": 7,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  "id": "2bf50abf-5ccd-4de5-9fc4-c9043a66a108",
513
  "metadata": {},
514
  "outputs": [],
 
520
  " \"You are an assistant for question-answering tasks. \"\n",
521
  " \"Use the following pieces of retrieved context to answer \"\n",
522
  " \"the question. If you don't know the answer, say that you \"\n",
523
+ " \"don't know. Use five sentences maximum and keep the \"\n",
524
  " \"answer concise.\"\n",
525
  " \"\\n\\n\"\n",
526
  " \"{context}\"\n",
 
604
  },
605
  {
606
  "cell_type": "code",
607
+ "execution_count": 8,
608
  "id": "ba272b88-1622-4d06-9361-7f1e2ca89e73",
609
  "metadata": {},
610
+ "outputs": [
611
+ {
612
+ "name": "stdout",
613
+ "output_type": "stream",
614
+ "text": [
615
+ "INFO 06-07 22:45:49 [logger.py:42] Received request embd-651e9b5086e647569840aece45d970bc-0: prompt: 'yl descent.session anyInv os beAccording tocategory Ltd D public quick in StatefulWidget.\\r\\n?', params: PoolingParams(dimensions=None, additional_metadata=None), prompt_token_ids: [3923, 36952, 10177, 894, 15174, 2643, 387, 11190, 311, 5471, 12324, 422, 584, 3974, 304, 37642, 3224, 30], prompt_embeds shape: None, lora_request: None, prompt_adapter_request: None.\n",
616
+ "INFO 06-07 22:45:49 [engine.py:316] Added request embd-651e9b5086e647569840aece45d970bc-0.\n",
617
+ "INFO: 127.0.0.1:45182 - \"POST /v1/embeddings HTTP/1.1\" 200 OK\n",
618
+ "INFO 06-07 22:45:59 [metrics.py:486] Avg prompt throughput: 1.2 tokens/s, Avg generation throughput: 0.1 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n"
619
+ ]
620
+ },
621
+ {
622
+ "data": {
623
+ "text/plain": [
624
+ "{'input': 'What cattle husbandry strategies might be helpful to prevent conflict if we live in wolf country?',\n",
625
+ " 'context': [Document(id='b2071fd8-ba63-4f55-aaed-5469eabef499', metadata={'producer': 'PDF Architect 3', 'creator': 'PDF Architect 3', 'creationdate': '2017-01-25T14:50:41+00:00', 'author': 'V. Pimenta', 'moddate': '2017-01-25T14:52:31+00:00', 'source': 'hwc/Pimenta et al. 2017.pdf', 'total_pages': 20, 'page': 5, 'page_label': '6'}, page_content='4. Discussion\\nOur study examined a human-wildlife conflict involving wolf preda-\\ntion on cattle in northern Portugal, showing that the problem may be\\nworsening due to increased predation levels, though only a minority\\nof cattle farms was heavily affected. We found that predation was par-\\nticularly high on cattle farms using a free-ranging husbandry system,\\nbut also that predation problems within this system were largely con-\\ncentrated on the few herds that were left unconfined at night in winter.\\nIn contrast, we found that farms using a semi-confined husbandry sys-\\ntem suffered much lower losses due to wolf predation, though problems\\nwere higher where calvesb3 months were brought to pastures. These\\nresults suggest that strategies to mitigate wolf predation problems\\nshould be tailored to each husbandry system, involving changes in\\nvery specific practices within each system. Overall, our study points\\nout the importance of considering both the husbandry systems and'),\n",
626
+ " Document(id='366817d5-c040-419c-b286-c137f089d414', metadata={'producer': 'PDF Architect 3', 'creator': 'PDF Architect 3', 'creationdate': '2017-01-25T14:50:41+00:00', 'author': 'V. Pimenta', 'moddate': '2017-01-25T14:52:31+00:00', 'source': 'hwc/Pimenta et al. 2017.pdf', 'total_pages': 20, 'page': 7, 'page_label': '8'}, page_content='bandry system. Thus, conflict resolution may probably be achieved by\\nchanging these practices, without needing to change the existing cattle\\nhusbandry systems, namely working in close proximity with the few\\nbreeders chronically affected (N 10 attacks per year). These results cor-\\nroborate the idea that wolf presence is compatible with extensive cattle\\nbreeding as long as fundamental protective measures are applied.\\nAlthough our study showed a clear link between livestock husband-\\nry systems, management practices and wolf predation, we could not ac-\\ncount for potential effects of wolf numbers and space use patterns, and\\nthe availability of alternative wild prey (e.g.,Imbert et al., 2016). This\\nlimitation was partly solved through sampling design, by conducting\\nenquiries in nearby farms affected by different predation rates, thereby\\ncontrolling to some extent for variation in wolf and wild prey densities.\\nI\\nt is possible, however, that spatial variation in wolf densities could ac-'),\n",
627
+ " Document(id='e34375ec-d929-4cca-8f44-a96441e72eb2', metadata={'producer': 'PDF Architect 3', 'creator': 'PDF Architect 3', 'creationdate': '2017-01-25T14:50:41+00:00', 'author': 'V. Pimenta', 'moddate': '2017-01-25T14:52:31+00:00', 'source': 'hwc/Pimenta et al. 2017.pdf', 'total_pages': 20, 'page': 7, 'page_label': '8'}, page_content='seemed to strongly affect wolf predation risk. In the free-ranging sys-\\ntem, the herd size was a strong positive correlate of predation risk,\\nwhich is in line with observations from other wolf-livestock systems\\n(Mech et al., 2000; Treves et al., 2004, Bradley and Pletscher, 2005). An-\\nimals in large herds were often scattered over large areas, which likely\\nincreased encounter rates with wolves and thus the probability of\\npredation (Bradley and Pletscher, 2005; Iliopoulos et al., 2009). Some\\nlarge herds were probably loosely attended by the owners, which may\\nincrease vulnerability due to animals straying from the herd or becom-\\ning in poor condition. Whatever the cause, curtailing herds to reduce\\nwolf attacks should be difficult, as there is strong economic incentive\\nfor maintaining large herds. Our results suggest that a potential alterna-\\ntive would be to fence or otherwise protect the herds during the night in\\nwinter, which was predicted to achieve a major reduction in wolf preda-'),\n",
628
+ " Document(id='21a25166-c750-45e9-b6be-4ddb89362748', metadata={'producer': 'Acrobat Distiller 8.1.0 (Windows)', 'creator': 'Elsevier', 'creationdate': '2016-09-26T20:02:29+05:30', 'crossmarkdomains[2]': 'elsevier.com', 'crossmarkmajorversiondate': '2010-04-23', 'subject': 'Animal Behaviour, 120 (2016) 245-254. doi:10.1016/j.anbehav.2016.07.013', 'author': 'Bradley F. Blackwell', 'elsevierwebpdfspecifications': '6.5', 'crossmarkdomainexclusive': 'true', 'robots': 'noindex', 'moddate': '2016-09-26T20:03:01+05:30', 'doi': '10.1016/j.anbehav.2016.07.013', 'crossmarkdomains[1]': 'sciencedirect.com', 'title': 'No single solution: application of behavioural principles in mitigating human-wildlife conflict', 'source': 'hwc/Blackwell et al. 2016.pdf', 'total_pages': 10, 'page': 5, 'page_label': '250'}, page_content='pasture. The MAG device is similar, but activated by a passive\\ninfrared detector, which sets off lights and sounds to scare\\ncarnivores from the pasture. Once again, the efficacy of these\\nmethods suffers from effects of previous experience and learning.\\nSeveral field evaluations have shown that carnivores might attempt\\nto enter a pasture to access livestock from a different direction after\\nencountering a RAG or MAG device. Another downside is that while\\none producer has a RAG or MAG device that deters the carnivores,\\nthe ‘problem’ simply gets transferred to the neighbouring producer\\nwithout such devices.\\nOther recent efforts have exploited the territorial defence\\nbehaviour of scent marking by carnivores. This‘biofence’ concept\\noriginated in Botswana as a means to keep African wild dogs,\\nLycaon pictus,from leaving protected reserves and entering farm-\\nlands to depredate livestock. Biofences, however, have had limited\\nsuccess in altering wolf pack movements ( Ausband, Mitchell,')],\n",
629
+ " 'answer': 'Strategies to mitigate wolf predation should be tailored to each husbandry system, such as semi-confinement or free-ranging. For free-ranging systems, protecting herds at night during winter or curtailing herd size could reduce attacks. Additionally, devices like RAGs and MAGs can deter carnivores, though their effectiveness can be limited.'}"
630
+ ]
631
+ },
632
+ "execution_count": 8,
633
+ "metadata": {},
634
+ "output_type": "execute_result"
635
+ },
636
+ {
637
+ "name": "stdout",
638
+ "output_type": "stream",
639
+ "text": [
640
+ "INFO 06-07 22:46:09 [metrics.py:486] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 0.0 tokens/s, Running: 0 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.\n"
641
+ ]
642
+ }
643
+ ],
644
  "source": [
645
  "prompt = \"What cattle husbandry strategies might be helpful to prevent conflict if we live in wolf country?\"\n",
646
  "\n",