Shagun Juthani commited on
Commit
2800072
·
1 Parent(s): c678860

Added my new file

Browse files
Files changed (1) hide show
  1. Embedding+Vector.ipynb +1110 -0
Embedding+Vector.ipynb ADDED
@@ -0,0 +1,1110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 21,
6
+ "id": "408e9000-977d-4f3f-a001-b06c55095c5f",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "## Handle secrets either from env vars or streamlit manager\n",
11
+ "import streamlit as st\n",
12
+ "import os\n",
13
+ "api_key = os.getenv(\"LITELLM_KEY\")\n",
14
+ "if api_key is None:\n",
15
+ " api_key = st.secrets[\"LITELLM_KEY\"]\n",
16
+ "cirrus_key = os.getenv(\"CIRRUS_KEY\")\n",
17
+ "if cirrus_key is None:\n",
18
+ " cirrus_key = st.secrets[\"CIRRUS_KEY\"] "
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 22,
24
+ "id": "802c676d-98c9-4e1f-b755-9eb6fbc09754",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "import os\n",
29
+ "import requests\n",
30
+ "import zipfile\n",
31
+ "\n",
32
+ "def download_and_unzip(url, output_dir):\n",
33
+ " response = requests.get(url)\n",
34
+ " zip_file_path = os.path.basename(url)\n",
35
+ " with open(zip_file_path, 'wb') as f:\n",
36
+ " f.write(response.content)\n",
37
+ " with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:\n",
38
+ " zip_ref.extractall(output_dir)\n",
39
+ " os.remove(zip_file_path)\n",
40
+ "\n",
41
+ "download_and_unzip(\"https://minio.carlboettiger.info/public-data/hwc.zip\", \"hwc\")"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 23,
47
+ "id": "00e3d915-4803-477f-9c19-db421cf129ac",
48
+ "metadata": {},
49
+ "outputs": [],
50
+ "source": [
51
+ "import pathlib\n",
52
+ "from langchain_community.document_loaders import PyPDFLoader\n",
53
+ "\n",
54
+ "def pdf_loader(path):\n",
55
+ " all_documents = []\n",
56
+ " docs_dir = pathlib.Path(path)\n",
57
+ " for file in docs_dir.iterdir():\n",
58
+ " loader = PyPDFLoader(file)\n",
59
+ " documents = loader.load()\n",
60
+ " all_documents.extend(documents)\n",
61
+ " return all_documents\n",
62
+ "\n",
63
+ "docs = pdf_loader('hwc/')"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 24,
69
+ "id": "d830b309-c047-491a-8114-ef9ad18dead5",
70
+ "metadata": {},
71
+ "outputs": [],
72
+ "source": [
73
+ "# NRP embedding model tends to throw errors\n",
74
+ "# embedding = OpenAIEmbeddings(model = \"embed-mistral\", api_key = api_key, base_url = \"https://llm.nrp-nautilus.io\")"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": 25,
80
+ "id": "4af17831-eb29-44c4-8a02-6d0cc996b70e",
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": [
84
+ "## Use the model on Cirrus instead:\n",
85
+ "\n",
86
+ "from langchain_openai import OpenAIEmbeddings\n",
87
+ "embedding = OpenAIEmbeddings(\n",
88
+ " model = \"cirrus\",\n",
89
+ " api_key = cirrus_key, \n",
90
+ " base_url = \"https://llm.cirrus.carlboettiger.info/v1\",\n",
91
+ ")"
92
+ ]
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "execution_count": 26,
97
+ "id": "efc963ed-d20d-49ce-b86c-05beb0947336",
98
+ "metadata": {},
99
+ "outputs": [],
100
+ "source": [
101
+ "# Build a retrival agent\n",
102
+ "from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
103
+ "text_splitter = RecursiveCharacterTextSplitter(chunk_size=5000, chunk_overlap=500)\n",
104
+ "splits = text_splitter.split_documents(docs)"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": 27,
110
+ "id": "bb5e99f3-3b58-423d-8945-bddc034c19fb",
111
+ "metadata": {},
112
+ "outputs": [],
113
+ "source": [
114
+ "# slow part here, runs on remote GPU\n",
115
+ "from langchain_core.vectorstores import InMemoryVectorStore\n",
116
+ "vectorstore = InMemoryVectorStore.from_documents(documents = splits, embedding = embedding)\n",
117
+ "retriever = vectorstore.as_retriever()"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": 28,
123
+ "id": "ad666954-aa66-40ac-a54e-2272f77f2d1c",
124
+ "metadata": {},
125
+ "outputs": [],
126
+ "source": [
127
+ "# Choose any of the models listed by their short-name:\n",
128
+ "# see `curl -H \"Authorization: Bearer $OPENAI_API_KEY\" https://llm.nrp-nautilus.io/v1/models`\n",
129
+ "\"\"\"\n",
130
+ "models = {\"llama3\": \"llama3-sdsc\", \n",
131
+ " \"deepseek-small\": \"DeepSeek-R1-Distill-Qwen-32B\",\n",
132
+ " \"deepseek\": \"deepseek-r1-qwen-qualcomm\",\n",
133
+ " \"gemma3\": \"gemma3\",\n",
134
+ " \"phi3\": \"phi3\",\n",
135
+ " \"olmo\": \"olmo\"\n",
136
+ " }\n",
137
+ "\"\"\"\n",
138
+ "from langchain_openai import ChatOpenAI\n",
139
+ "#llm = ChatOpenAI(model = models['gemma3'],\n",
140
+ " #api_key = api_key, \n",
141
+ " #base_url = \"https://llm.nrp-nautilus.io\", \n",
142
+ " #temperature=0)\n",
143
+ "\n",
144
+ "\n",
145
+ "from langchain.chains import create_retrieval_chain\n",
146
+ "from langchain.chains.combine_documents import create_stuff_documents_chain\n",
147
+ "from langchain_core.prompts import ChatPromptTemplate\n",
148
+ "\n",
149
+ "system_prompt = (\n",
150
+ " \"You are an assistant for question-answering tasks. \"\n",
151
+ " \"Use the following scientific articles as the retrieved context to answer \"\n",
152
+ " \"the question. Appropriately cite the articles from the context on which your answer is based using (Author, Year) format. \"\n",
153
+ " \"Do not attempt to cite articles that are not in the context.\"\n",
154
+ " \"If you don't know the answer, say that you don't know.\"\n",
155
+ " \"Use up to five sentences maximum and keep the answer concise.\\n\\n\"\n",
156
+ " \"{context}\"\n",
157
+ ")\n",
158
+ "\"\"\"\n",
159
+ "prompt = ChatPromptTemplate.from_messages(\n",
160
+ " [\n",
161
+ " (\"system\", system_prompt),\n",
162
+ " (\"human\", \"{input}\"),\n",
163
+ " ]\n",
164
+ ")\n",
165
+ "question_answer_chain = create_stuff_documents_chain(retriever, prompt)\n",
166
+ "rag_chain = create_retrieval_chain(retriever, question_answer_chain)\n",
167
+ "\"\"\"\n",
168
+ "\n",
169
+ "#call the retriever by ourselves\n",
170
+ "def test_retriever_only(query: str, k: int = 5):\n",
171
+ " retriever.search_kwargs[\"k\"] = k \n",
172
+ " retrieved_docs = retriever.invoke(query)\n",
173
+ " \n",
174
+ " print(f\"\\n Query: {query}\")\n",
175
+ " print(f\"\\n Top {k} Retrieved Documents:\\n\" + \"-\"*60)\n",
176
+ " \n",
177
+ " for i, doc in enumerate(retrieved_docs):\n",
178
+ " print(f\"\\n--- Document #{i+1} ---\")\n",
179
+ " print(doc.page_content[:1000]) \n",
180
+ " if hasattr(doc, \"metadata\") and doc.metadata:\n",
181
+ " print(\"\\n[Metadata]:\", doc.metadata)"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "code",
186
+ "execution_count": 29,
187
+ "id": "e59dc0c7-5f40-4994-b925-11e4a6605a7a",
188
+ "metadata": {},
189
+ "outputs": [
190
+ {
191
+ "name": "stdout",
192
+ "output_type": "stream",
193
+ "text": [
194
+ "\n",
195
+ " Query: I live in Tanzania and am having issues with lions breaking into my boma and preying on cattle. What are a few ways to help me prevent this from happening in the future? Can you check these pdfs to see which ones might help?\n",
196
+ "\n",
197
+ " Top 5 Retrieved Documents:\n",
198
+ "------------------------------------------------------------\n",
199
+ "\n",
200
+ "--- Document #1 ---\n",
201
+ "hypothesis was that index of pre- and post-ban use\n",
202
+ "was the same for both types of feeding sites.\n",
203
+ "We calculated the average annual number of\n",
204
+ "observed bears during pre- and post-ban periods\n",
205
+ "for each feeding site. We then used these averages\n",
206
+ "instead of raw data from individual counts. We\n",
207
+ "calculated an annual index of feeding site use by\n",
208
+ "pooling data from all feeding sites (average number\n",
209
+ "of bears counted at feeding sites in post-ban period\n",
210
+ "divided by average number of bears counted in pre-\n",
211
+ "ban period). Subsequently, we used bootstrapping\n",
212
+ "with 1,000 simulations to test for differences between\n",
213
+ "SUPPLEMENTAL FEEDING AND BEAR DEPREDATIONS N Kavcˇicˇ et al. 113\n",
214
+ "Ursus 24(2):111–119 (2013)\n",
215
+ "\n",
216
+ "[Metadata]: {'producer': 'GPL Ghostscript 9.26', 'creator': '', 'creationdate': '2022-06-06T23:09:49-07:00', 'moddate': '2022-06-06T23:09:49-07:00', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'source': 'hwc\\\\Kavcic et al. 2013.pdf', 'total_pages': 9, 'page': 2, 'page_label': '3'}\n",
217
+ "\n",
218
+ "--- Document #2 ---\n",
219
+ "ESPINOSA AND JACOBSON 59\n",
220
+ "TABLE 3\n",
221
+ "Linear Multiple Regressions Showing the Association of Variables With People’s Attitudes, Behavioral\n",
222
+ "Intentions and Perceived Program Impacts\n",
223
+ "A) Attitude B) Attitude C) Behavioral\n",
224
+ "toward toward intention in a D) Bear Project\n",
225
+ "bear protection bear presence conflict with a bear support\n",
226
+ "Explanatory Std. Beta Std. Beta Std. Beta Std. Beta\n",
227
+ "variables coefficient Sig. coefficient Sig. coefficient Sig. coefficient Sig.\n",
228
+ "Gender∗ −.137 .182 −.302 .010 −.544 .000 −.339 .002\n",
229
+ "Age −.154 .076 .001 .995 .016 .855 .026 .778\n",
230
+ "Monthly income −.108 .180 .081 .367 −.036 .643 .189 .027\n",
231
+ "Cow predation by\n",
232
+ "bears∗∗\n",
233
+ "−.139 .077 −.196 .028 −.024 .754 .001 .994\n",
234
+ "Environmental\n",
235
+ "knowledge\n",
236
+ ".484 .000 .189 .144 .235 .037 .182 .117\n",
237
+ "Participation in\n",
238
+ "Bear Project∗∗\n",
239
+ ".145 .087 .149 .132 .063 .447 .387 .000\n",
240
+ "Adjusted R2 .266 .081 .159 .232\n",
241
+ "SE of the estimate .773 1 .108 .916 .850\n",
242
+ "N 121 121 145 114\n",
243
+ "∗Male = 1, Female = 0; ∗∗ Yes = 1, No = 0.\n",
244
+ "each lasting approximately 1.5 hrs, were conducted with teachers (\n",
245
+ "\n",
246
+ "[Metadata]: {'producer': 'Acrobat Distiller 6.0.1 (Windows)', 'creator': 'dvips(k) 5.95a Copyright 2005 Radical Eye Software', 'creationdate': '2011-11-09T13:01:02+05:30', 'moddate': '2011-11-09T13:01:23+05:30', 'title': 'Human-Wildlife Conflict and Environmental Education: Evaluating a Community Program to Protect the A', 'source': 'hwc\\\\Espinosa et al. 2011.pdf', 'total_pages': 12, 'page': 5, 'page_label': '59'}\n",
247
+ "\n",
248
+ "--- Document #3 ---\n",
249
+ "KEYWORDS\n",
250
+ "bio-logging, crop guarding, crop-foraging, fencing, home range, human-wildlife conflict\n",
251
+ "mitigation, primate, raiding frequency, social sciences, space use\n",
252
+ "1 | INTRODUCTION\n",
253
+ "With an expanding human population that is encroach-\n",
254
+ "ing on natural landscapes, negative interactions between\n",
255
+ "people and wildlife are increasing. Such interactions are\n",
256
+ "more marked when wildlife searches for and consumes\n",
257
+ "food resources in farmlands (Warren et al.,\n",
258
+ "2007; Webber\n",
259
+ "et al.,2011) and urban areas (Contesse et al.,2004; Yeo &\n",
260
+ "Neo, 2010). Crop and urban foraging wildlife can result\n",
261
+ "in severe economic losses for people because of the dam-\n",
262
+ "age they cause to crops and infrastructure (Tavolaro\n",
263
+ "et al., 2022) contributing to negative human –wildlife\n",
264
+ "interactions and feelings of insecurity by people, espe-\n",
265
+ "cially when large mammals or carnivore species forage in\n",
266
+ "human spaces (Soulsbury & White, 2016). For wildlife,\n",
267
+ "these interactions can pose significant welfare costs and\n",
268
+ "threaten populations of endangered sp\n",
269
+ "\n",
270
+ "[Metadata]: {'producer': 'Acrobat Distiller 11.0 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': 'Arbortext Advanced Print Publisher 9.1.520/W Unicode', 'creationdate': '2023-06-16T15:56:20+05:30', 'keywords': '', 'moddate': '2025-05-27T12:15:01-07:00', 'subject': 'Conservat Sci and Prac 2023.5:e12948', 'wps-proclevel': '3', 'wps-journaldoi': '10.1111/(ISSN)2578-4854', 'title': 'Using behavioral studies to adapt management decisions and reduce negative interactions between humans and baboons in Cape Town, South Africa', 'wps-articledoi': '10.1111/csp2.12948', 'source': 'hwc\\\\Fehlmann et al. 2022.pdf', 'total_pages': 16, 'page': 1, 'page_label': '2'}\n",
271
+ "\n",
272
+ "--- Document #4 ---\n",
273
+ "and among lethal interventions, 48.6% investigated culling (N =1 7 ) ,\n",
274
+ "34.3% retaliatory killing (N = 12), and 17.1% trophy-hunting (N =6 ) .\n",
275
+ "Contrary to the whole body of literature, most of these case studies were\n",
276
+ "located in the Neartic (63.6%) followed by the Afrotropic (24.5%) and\n",
277
+ "Paleartic (7.7%) (Fig. 3). Nonetheless, the species included in the case studies\n",
278
+ "reflected the generalfindings, with most of the management experiments\n",
279
+ "being conducted on wolves (29.4%) followed by bears (23.8%) and leopards\n",
280
+ "(16.1%) (Fig. 2). Surprisingly, almost none of the experiments were con-\n",
281
+ "ducted on tigers, despite their strong presence in the whole literature and\n",
282
+ "their heavy impact, including attacks on humans (Dhungana et al., 2016).\n",
283
+ "Fig. 2.Species prevalence in literature (black bars,N = 525) and case studies (gray bars, N = 143).\n",
284
+ "Fig. 3.Geographic prevalence in literature (black bars, N = 525) and case studies (gray bars,N = 143), with species involved per geographic area. In circles, mean result\n",
285
+ "\n",
286
+ "[Metadata]: {'producer': 'PyPDF', 'creator': 'Elsevier', 'creationdate': '2022-06-07T02:40:21+00:00', 'author': 'Charlotte Lorand', 'crossmarkdomains[1]': 'elsevier.com', 'crossmarkdomains[2]': 'sciencedirect.com', 'crossmarkdomainexclusive': 'true', 'crossmarkmajorversiondate': '2010-04-23', 'elsevierwebpdfspecifications': '7.0', 'keywords': 'Human-carnivore coexistence; Lethal control; Non-lethal management; Conservation interventions; Effectiveness; Evidence-based', 'moddate': '2022-06-07T02:40:21+00:00', 'subject': 'Science of the Total Environment, 838 (2022) 156195. doi:10.1016/j.scitotenv.2022.156195', 'title': \"Effectiveness of interventions for managing human-large carnivore conflicts worldwide: Scare them off, don't remove them\", 'doi': '10.1016/j.scitotenv.2022.156195', 'robots': 'noindex', 'source': 'hwc\\\\Lorand et al. 2022.pdf', 'total_pages': 11, 'page': 5, 'page_label': '6'}\n",
287
+ "\n",
288
+ "--- Document #5 ---\n",
289
+ "because they have longer perimeters (Fig. 1B). Finally, 80–85% of\n",
290
+ "the cost of materials of most fences is in the corner and end systems;\n",
291
+ "therefore, an effort should be made to minimize these.\n",
292
+ "We designed a computer model to assist with determining if\n",
293
+ "fencing is economically feasible for reducing deer damage and, if\n",
294
+ "so, which fence design would be optimal (VerCauteren et al.\n",
295
+ "2006). Our interactive model provides economic analyses and\n",
296
+ "predicts the scenarios associated with fencing relative to area and\n",
297
+ "perimeter of the protected plot, value and percentage of crop\n",
298
+ "damaged annually prior to fencing, cost of the fence, and efficacy\n",
299
+ "of the fence. Users of the model can easily adjust the above\n",
300
+ "variables to fit their individual situations and needs. By running a\n",
301
+ "series of simulations, users can answer questions directly related to\n",
302
+ "the economics associated with different fence designs for their\n",
303
+ "situation.\n",
304
+ "Negative Impacts\n",
305
+ "Fences can effectively protect human commodities; however, they\n",
306
+ "can have neg\n",
307
+ "\n",
308
+ "[Metadata]: {'producer': 'PDFlib PLOP 2.0.0p6 (SunOS)/Acrobat Distiller 6.0 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': '3B2 Total Publishing System 8.07c/W', 'creationdate': '2006-04-19T19:41:41-05:00', 'moddate': '2025-05-27T12:08:26-07:00', 'subject': 'Wildlife Society Bulletin 2006.34:191-200', 'wps-proclevel': '2', 'wps-journaldoi': '10.1111/wsb4.2006.34.issue-1', 'title': 'From the Field: Fences and Deer‐Damage Management: A Review of Designs and Efficacy', 'wps-articledoi': '10.2193/0091-7648(2006)34[191:FADMAR]2.0.CO;2', 'source': 'hwc\\\\VerCauteren et al. 2006.pdf', 'total_pages': 10, 'page': 3, 'page_label': '4'}\n"
309
+ ]
310
+ },
311
+ {
312
+ "data": {
313
+ "text/plain": [
314
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
315
+ ]
316
+ },
317
+ "execution_count": 29,
318
+ "metadata": {},
319
+ "output_type": "execute_result"
320
+ }
321
+ ],
322
+ "source": [
323
+ "test_query = \"I live in Tanzania and am having issues with lions breaking into my boma and preying on cattle. What are a few ways to help me prevent this from happening in the future? Can you check these pdfs to see which ones might help?\"\n",
324
+ "test_retriever_only(test_query, k=5)\n",
325
+ "test_retriever_only"
326
+ ]
327
+ },
328
+ {
329
+ "cell_type": "code",
330
+ "execution_count": 30,
331
+ "id": "968cd90b-0bc6-42f9-a097-97d3f347d93e",
332
+ "metadata": {},
333
+ "outputs": [
334
+ {
335
+ "name": "stdout",
336
+ "output_type": "stream",
337
+ "text": [
338
+ "\n",
339
+ " Query: What should I do if elephants are destroying my crops? And what are the most cost-effective prevention methods, if there are any you know of? Can you check these pdfs to see which ones might help?\n",
340
+ "\n",
341
+ " Top 5 Retrieved Documents:\n",
342
+ "------------------------------------------------------------\n",
343
+ "\n",
344
+ "--- Document #1 ---\n",
345
+ "hypothesis was that index of pre- and post-ban use\n",
346
+ "was the same for both types of feeding sites.\n",
347
+ "We calculated the average annual number of\n",
348
+ "observed bears during pre- and post-ban periods\n",
349
+ "for each feeding site. We then used these averages\n",
350
+ "instead of raw data from individual counts. We\n",
351
+ "calculated an annual index of feeding site use by\n",
352
+ "pooling data from all feeding sites (average number\n",
353
+ "of bears counted at feeding sites in post-ban period\n",
354
+ "divided by average number of bears counted in pre-\n",
355
+ "ban period). Subsequently, we used bootstrapping\n",
356
+ "with 1,000 simulations to test for differences between\n",
357
+ "SUPPLEMENTAL FEEDING AND BEAR DEPREDATIONS N Kavcˇicˇ et al. 113\n",
358
+ "Ursus 24(2):111–119 (2013)\n",
359
+ "\n",
360
+ "[Metadata]: {'producer': 'GPL Ghostscript 9.26', 'creator': '', 'creationdate': '2022-06-06T23:09:49-07:00', 'moddate': '2022-06-06T23:09:49-07:00', 'title': '', 'author': '', 'subject': '', 'keywords': '', 'source': 'hwc\\\\Kavcic et al. 2013.pdf', 'total_pages': 9, 'page': 2, 'page_label': '3'}\n",
361
+ "\n",
362
+ "--- Document #2 ---\n",
363
+ "ESPINOSA AND JACOBSON 59\n",
364
+ "TABLE 3\n",
365
+ "Linear Multiple Regressions Showing the Association of Variables With People’s Attitudes, Behavioral\n",
366
+ "Intentions and Perceived Program Impacts\n",
367
+ "A) Attitude B) Attitude C) Behavioral\n",
368
+ "toward toward intention in a D) Bear Project\n",
369
+ "bear protection bear presence conflict with a bear support\n",
370
+ "Explanatory Std. Beta Std. Beta Std. Beta Std. Beta\n",
371
+ "variables coefficient Sig. coefficient Sig. coefficient Sig. coefficient Sig.\n",
372
+ "Gender∗ −.137 .182 −.302 .010 −.544 .000 −.339 .002\n",
373
+ "Age −.154 .076 .001 .995 .016 .855 .026 .778\n",
374
+ "Monthly income −.108 .180 .081 .367 −.036 .643 .189 .027\n",
375
+ "Cow predation by\n",
376
+ "bears∗∗\n",
377
+ "−.139 .077 −.196 .028 −.024 .754 .001 .994\n",
378
+ "Environmental\n",
379
+ "knowledge\n",
380
+ ".484 .000 .189 .144 .235 .037 .182 .117\n",
381
+ "Participation in\n",
382
+ "Bear Project∗∗\n",
383
+ ".145 .087 .149 .132 .063 .447 .387 .000\n",
384
+ "Adjusted R2 .266 .081 .159 .232\n",
385
+ "SE of the estimate .773 1 .108 .916 .850\n",
386
+ "N 121 121 145 114\n",
387
+ "∗Male = 1, Female = 0; ∗∗ Yes = 1, No = 0.\n",
388
+ "each lasting approximately 1.5 hrs, were conducted with teachers (\n",
389
+ "\n",
390
+ "[Metadata]: {'producer': 'Acrobat Distiller 6.0.1 (Windows)', 'creator': 'dvips(k) 5.95a Copyright 2005 Radical Eye Software', 'creationdate': '2011-11-09T13:01:02+05:30', 'moddate': '2011-11-09T13:01:23+05:30', 'title': 'Human-Wildlife Conflict and Environmental Education: Evaluating a Community Program to Protect the A', 'source': 'hwc\\\\Espinosa et al. 2011.pdf', 'total_pages': 12, 'page': 5, 'page_label': '59'}\n",
391
+ "\n",
392
+ "--- Document #3 ---\n",
393
+ "Americas. In recent decades, extensive fragmentation of\n",
394
+ "jaguar habitat and expansion of human activities into such\n",
395
+ "areas has increased both jaguar depredation on livestock as\n",
396
+ "well as conflict with humans (Rabinowitz and Nottingham\n",
397
+ "1986, Weber and Rabinowitz 1996). However, there has\n",
398
+ "been limited assessment of the magnitude of jaguar use of\n",
399
+ "livestock as prey or of factors predisposing livestock to\n",
400
+ "depredation by jaguars. For instance, the demonstrated\n",
401
+ "preference by jaguars for forested habitats in close\n",
402
+ "association with standing water is attributed to increased\n",
403
+ "wild prey vulnerability to predation in such habitats\n",
404
+ "(Crawshaw and Quigley 1991, Quigley and Crawshaw\n",
405
+ "1992). Similar patterns may apply to jaguar selection of\n",
406
+ "domestic prey. Inappropriate husbandry practices and wild\n",
407
+ "prey availability and vulnerability are factors reported to\n",
408
+ "influence vulnerability of livestock to depredation by jaguars,\n",
409
+ "particularly among calves (Quigley and Crawshaw 1992,\n",
410
+ "Hoogesteijn et al. 1993, Polisar et al.\n",
411
+ "\n",
412
+ "[Metadata]: {'producer': 'PDFlib PLOP 2.0.0p6 (SunOS)/Acrobat Distiller 7.0.5 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': '3B2 Total Publishing System 8.07c/W', 'creationdate': '2007-08-21T03:47:13-05:00', 'moddate': '2025-05-27T11:54:37-07:00', 'subject': 'J Wildl Manag 2007.71:2379-2386', 'wps-proclevel': '2', 'wps-journaldoi': '10.1111/jwmg.2007.71.issue-7', 'title': 'Evaluation of Potential Factors Predisposing Livestock to Predation by Jaguars', 'wps-articledoi': '10.2193/2006-520', 'source': 'hwc\\\\Azevedo and Murray 2007.pdf', 'total_pages': 8, 'page': 0, 'page_label': '1'}\n",
413
+ "\n",
414
+ "--- Document #4 ---\n",
415
+ "Convention on the Conservation of European Wildlife and Natural HabitatsNature\n",
416
+ "and Environment Series 113. Council of Europe, Strasbourg.\n",
417
+ "Boitani, L., Ciucci, P., Raganella-Pelliccioni, E., 2010.Ex-post compensation payments for\n",
418
+ "wolf predation on livestock in Italy: a tool for conservation? Wildl. Res. 37, 722–730.\n",
419
+ "Bradley, E.H., Pletscher, D.H., 2005.Assessing factors related to wolf depredation of cattle\n",
420
+ "in fenced pastures in Montana and Idaho. Wildl. Soc. Bull. 33, 1256–1265.\n",
421
+ "Breck, S.W., Meier, T., 2004.Managing wolf depredation in the United States: past, pres-\n",
422
+ "ent, and future. Sheep Goat Res. J. 19 (Special Issue: Predation), 41–46.\n",
423
+ "Burnham, K.P., Anderson, D.R., 2002.Model Selection and Multimodel Inference. A Practi-\n",
424
+ "cal Information-Theoretic Approach. Springer-Verlag.\n",
425
+ "Cade, B.S., 2015.Model averaging and muddled multimodel inferences. Ecology 96,\n",
426
+ "2370–2382.\n",
427
+ "Chapron, G., Kaczensky, P., Linnell, J.D., von Arx, M., Huber, D., Andrén, H., ... Boitani, L.,\n",
428
+ "2014. Recovery of large c\n",
429
+ "\n",
430
+ "[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': 8, 'page_label': '9'}\n",
431
+ "\n",
432
+ "--- Document #5 ---\n",
433
+ "attacked bomas ranged from 54% (at 0–1 km); 31% (at 1–2 km); 11% (at 2–3 km) to 4% (at >3\n",
434
+ "km from the park boundary). We also found a significant yearly increase in mean distance of\n",
435
+ "attacks from the park boundary, from the application of flashlights in 2012 (Mann-Whitney U\n",
436
+ "test t = 11.291, df = 79.002, p-value = 0.0001) (Fig 7). The yearly regression with intercept of\n",
437
+ "2.001+03 and slope of 0.008, shows that every 3 years, there is 2km increase in distance of\n",
438
+ "attack.\n",
439
+ "The fence height in relation to percentages of attack (high = 12%, medium 23%, short =\n",
440
+ "71% and χ\n",
441
+ "2\n",
442
+ "= 8.088, df = 2, p-value = 0.017.This shows that bomas without flashlights and\n",
443
+ "those with short-medium fences are more likely to be attacked by lion than those with flash-\n",
444
+ "lights and higher fences. The data normality distribution test was W = 0.87567, p-value <\n",
445
+ "0.00001.\n",
446
+ "Fig 5. Cumulative flashlights installed and Mean nocturnal and diurnal livestock predation at bomas with and without\n",
447
+ "flashlights .\n",
448
+ "https://do i.org/10.1371/j o\n",
449
+ "\n",
450
+ "[Metadata]: {'producer': 'PDFlib+PDI 8.0.2p1 (C++/Win64); modified using iTextSharp™ 5.5.3 ©2000-2014 iText Group NV (AGPL-version)', 'creator': 'Arbortext Advanced Print Publisher 11.0.2857/W Unicode-x64', 'creationdate': '2018-01-10T21:11:13+05:30', 'title': 'Effectiveness of a LED flashlight technique in reducing livestock depredation by lions (Panthera leo) around Nairobi National Park, Kenya', 'eps_processor': 'PStill version 1.76.22', 'moddate': '2018-01-10T21:12:24+05:30', 'author': \"Francis Lesilau, Myrthe Fonck, Maria Gatta, Charles Musyoki, Maarten van 't Zelfde, Gerard A. Persoon, Kees C. J. M. Musters, Geert R. de Snoo, Hans H. de Iongh\", 'source': 'hwc\\\\Lesilau et al. 2018.pdf', 'total_pages': 18, 'page': 9, 'page_label': '10'}\n"
451
+ ]
452
+ },
453
+ {
454
+ "data": {
455
+ "text/plain": [
456
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
457
+ ]
458
+ },
459
+ "execution_count": 30,
460
+ "metadata": {},
461
+ "output_type": "execute_result"
462
+ }
463
+ ],
464
+ "source": [
465
+ "test_query = \"What should I do if elephants are destroying my crops? And what are the most cost-effective prevention methods, if there are any you know of? Can you check these pdfs to see which ones might help?\"\n",
466
+ "test_retriever_only(test_query, k=5)\n",
467
+ "test_retriever_only"
468
+ ]
469
+ },
470
+ {
471
+ "cell_type": "code",
472
+ "execution_count": 31,
473
+ "id": "327f96c5-2656-4ed6-8bba-2bd4bd652f83",
474
+ "metadata": {},
475
+ "outputs": [
476
+ {
477
+ "name": "stdout",
478
+ "output_type": "stream",
479
+ "text": [
480
+ "\n",
481
+ " Query: I know jaguars can prey on goats and cattle, which I have; what measures can I take to save them from getting harmed? Can you check these pdfs to see which ones might help? \n",
482
+ "\n",
483
+ " Top 5 Retrieved Documents:\n",
484
+ "------------------------------------------------------------\n",
485
+ "\n",
486
+ "--- Document #1 ---\n",
487
+ "458 SELECTIVE REMOVAL OF COYOTES * Blejwas et al. J. Wildl. Manage. 66(2):2002 \n",
488
+ " was monitored, predation resumed only after the \n",
489
+ " new pair had formed (K. M. Blejwas, unpublished \n",
490
+ " data). These data suggest that loss of a mate and \n",
491
+ " the associated process of forming a new pair \n",
492
+ " bond alters the behavior of the surviving breeder, \n",
493
+ " temporarily interrupting predation on sheep. \n",
494
+ " Why Breeding Coyotes Kill Sheep \n",
495
+ " It is not surprising that breeding pairs are \n",
496
+ " responsible for most depredations of ewes and \n",
497
+ " large lambs. Most observations of coyotes attack- \n",
498
+ " ing large ungulate prey indicate that these are \n",
499
+ " cooperative endeavors involving more than 1 coy- \n",
500
+ " ote (Cahalane 1947, Robinson 1952, Bowyer \n",
501
+ " 1987, Gese and Grothe 1995, Lingle 2000). Most \n",
502
+ " observations of coyotes attacking ungulate fawns \n",
503
+ " also involve pairs or groups of coyotes (Mac- \n",
504
+ " Connell-Yount and Smith 1978, Hamlin and \n",
505
+ " Schweitzer 1979, Truett 1979, Bowyer 1987), and \n",
506
+ " a pair may be present even when only 1 coyote is \n",
507
+ " in\n",
508
+ "\n",
509
+ "[Metadata]: {'producer': 'iText® 5.5.8 ©2000-2015 iText Group NV (AGPL-version); modified using iText® 7.1.3 ©2000-2018 iText Group NV (JSTOR Michigan; licensed version)', 'creator': 'page2pdf-2.1', 'creationdate': '2016-08-07T19:47:10+00:00', 'moddate': '2020-09-14T14:51:37+00:00', 'title': 'The Effectiveness of Selective Removal of Breeding Coyotes in Reducing Sheep Predation', 'source': 'hwc\\\\Blejwas et al. 2002.pdf', 'total_pages': 13, 'page': 8, 'page_label': '459'}\n",
510
+ "\n",
511
+ "--- Document #2 ---\n",
512
+ "Gittleman, J.L., Funk, S.M., Macdonald, D.W. & Wayne,\n",
513
+ "R.K. (2001). Why ‘carnivore conservation’? InCarnivore\n",
514
+ "conservation: 1–8. Gittleman, J.L., Funk, S.M., Macdo-\n",
515
+ "nald, D. & Wayne, R.K. (Eds). Cambridge: Cambridge\n",
516
+ "University Press.\n",
517
+ "Gonz ´alez, F. (1995). Livestock predation in the Venezuelan\n",
518
+ "Llanos. Cat News 22, 14–15.\n",
519
+ "Hoogesteijn, R., Hoogesteijn, A. & Mondolfi, E. (1993).\n",
520
+ "Jaguar predation and conservation: cattle mortality caused\n",
521
+ "by felines on three ranches in the Venezuelan Llanos. In\n",
522
+ "Mammals as predators : 391–407. Dunstone, N. & Gorman,\n",
523
+ "M.L. (Eds). London: Oxford University Press.\n",
524
+ "Hoogesteijn, R. & Mondolfi, E. (1992).The jaguar. Caracas:\n",
525
+ "Armitano Publishers.\n",
526
+ "Instituto Brasileiro de Geografia e Estat´ıstica (IBGE). (2004)\n",
527
+ "Pesquisa Pecu´aria Municipal 1990–2003. Available at\n",
528
+ "http://www.ibge.gov.br/bda/pecua.\n",
529
+ "Iriarte, J.A., Johnson, W.E. & Franklin, W.L. (1991). Feeding\n",
530
+ "ecology of the Patagonia puma in southernmost Chile.Rev.\n",
531
+ "Chil. Hist. Nat. 64, 145–156.\n",
532
+ "Jackson, R., Wang, Z.Y., Lu, \n",
533
+ "\n",
534
+ "[Metadata]: {'producer': 'PDFlib PLOP 3.0 (.NET/Win32)/Acrobat Distiller 6.0.1 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': '3B2 Total Publishing System 8.07f/W', 'creationdate': '2006-03-25T19:46:31+05:30', 'moddate': '2025-05-27T11:47:43-07:00', 'subject': 'Animal Conservation 2006.9:179-188', 'wps-proclevel': '2', 'title': 'Human��wildlife conflicts in a fragmented Amazonian forest landscape: determinants of large felid depredation on livestock', 'wps-articledoi': '10.1111/j.1469-1795.2006.00025.x', 'source': 'hwc\\\\Michalski et al. 2006.pdf', 'total_pages': 10, 'page': 8, 'page_label': '9'}\n",
535
+ "\n",
536
+ "--- Document #3 ---\n",
537
+ "See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/305358233\n",
538
+ "Fencing: A Valuable Tool for Reducing Wildlife-Vehicle Collisions and\n",
539
+ "Funnelling Fauna to Crossing Structures\n",
540
+ "Chapter · January 2015\n",
541
+ "DOI: 10.1002/9781118568170.ch20\n",
542
+ "CITATIONS\n",
543
+ "54\n",
544
+ "READS\n",
545
+ "3,350\n",
546
+ "3 authors, including:\n",
547
+ "Rodney van der Ree\n",
548
+ "University of Melbourne\n",
549
+ "148 PUBLICATIONS   5,823 CITATIONS   \n",
550
+ "SEE PROFILE\n",
551
+ "All content following this page was uploaded by Rodney van der Ree on 23 July 2018.\n",
552
+ "The user has requested enhancement of the downloaded file.\n",
553
+ "\n",
554
+ "[Metadata]: {'producer': 'PDFlib PLOP 2.0.0p6 (SunOS)/iTextSharp™ 5.5.0 ©2000-2013 iText Group NV (AGPL-version)', 'creator': 'PyPDF', 'creationdate': '2015-03-24T09:28:20+05:30', 'title': 'Fencing', 'wps-articledoi': '10.1002/9781118568170.ch20', 'wps-proclevel': '3', 'moddate': '2015-04-24T21:50:27-04:00', 'author': 'Rodney van der Ree', 'rgid': 'PB:305358233_AS:651478247145472@1532335926046', 'source': 'hwc\\\\van der Ree et al. 2015.pdf', 'total_pages': 14, 'page': 0, 'page_label': '159'}\n",
555
+ "\n",
556
+ "--- Document #4 ---\n",
557
+ "timating the percent loss of kernels (Woronecki et al.\n",
558
+ "1980) and converting to yield loss per hectare. Fruit loss\n",
559
+ "can be estimated by counting the numbers of undamaged,\n",
560
+ "pecked, and removed fruits per sampled branch (Tobin\n",
561
+ "and Dolbeer 1987). Sprouting rice removed by birds can\n",
562
+ "be estimated by companng plant density in exposed plots\n",
563
+ "with that in adjacent plots with wire bird exclosures (Otis\n",
564
+ "et al. 1983). The seeded surface area of sunflower heads\n",
565
+ "destroyed by birds can be estimated with the aid of a clear\n",
566
+ "plastic template (Dolbeer 1975).\n",
567
+ "Losses of agricultural crops to birds can be estimated\n",
568
+ "indirectly through avian bioenergetics. By estimating the\n",
569
+ "number of birds of the depredating species feeding in an\n",
570
+ "area, thc percentage of thc agncultural crop in the birds'\n",
571
+ "diet, the caloric value of the crop, and the daily caloric\n",
572
+ "requirements of the birds, one can project thc total bio-\n",
573
+ "mass of crop removed by birds on a daily or seasonal\n",
574
+ "basis (Weathcrhead et al. 1982, White et al. 1985).\n",
575
+ "Specie\n",
576
+ "\n",
577
+ "[Metadata]: {'producer': 'Canon iR C5800', 'creator': 'Canon iR C5800', 'creationdate': '2009-03-09T08:39:40-05:00', 'subject': 'Image', 'source': 'hwc\\\\Dolbeer et al. 1994.pdf', 'total_pages': 34, 'page': 2, 'page_label': '3'}\n",
578
+ "\n",
579
+ "--- Document #5 ---\n",
580
+ "7,3 1 7e325\n",
581
+ ".\n",
582
+ "Hovick, T. J., Elmore, R. D., Dahlgren, D. K., Fuhlendorf, S. D., & Engle, D. M. (2014).\n",
583
+ "Evidence of negative effects of anthropogenic structures on wildlife: A review of\n",
584
+ "grouse survival and behaviour.Journal of Applied Ecology, 51, 1680e1689.\n",
585
+ "Huijser, M., McGowen, P., Fuller, J., Hardy, A., Kociolek, A., Clevenger, A. P., et al.\n",
586
+ "(2008). Wildlifeevehicle collision reduction study: Report to congress [No.\n",
587
+ "FHWAeHRTe08e034]. Washington, D.C.: U.S. Department of Transportation.\n",
588
+ "Hunt, W. G., McClure, C. J. W., & Allison, T. D. (2015). Do raptors react to ultraviolet\n",
589
+ "light? Journal of Raptor Research, 49, 342e343.\n",
590
+ "Jaeger, M. M., Blejwas, K. M., Sacks, B. N., Neale, J. C. C., Conner, M. M., &\n",
591
+ "McCullough, D. R. (2001). Targeting alphas can make coyote control more\n",
592
+ "effective and socially acceptable.California Agriculture, 55,3 2e36.\n",
593
+ "Johnson, H. E., Breck, S. W., Baruch-Mordo, S., Lewis, D. L., Lackey, C. W.,\n",
594
+ "Wilson, K. R., et al. (2015). Shifting perceptions of risk and reward: Te\n",
595
+ "\n",
596
+ "[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': 8, 'page_label': '253'}\n"
597
+ ]
598
+ },
599
+ {
600
+ "data": {
601
+ "text/plain": [
602
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
603
+ ]
604
+ },
605
+ "execution_count": 31,
606
+ "metadata": {},
607
+ "output_type": "execute_result"
608
+ }
609
+ ],
610
+ "source": [
611
+ "test_query = \"I know jaguars can prey on goats and cattle, which I have; what measures can I take to save them from getting harmed? Can you check these pdfs to see which ones might help? \"\n",
612
+ "test_retriever_only(test_query, k=5)\n",
613
+ "test_retriever_only"
614
+ ]
615
+ },
616
+ {
617
+ "cell_type": "code",
618
+ "execution_count": 32,
619
+ "id": "5afb060d-0444-4167-bdd5-b63501475773",
620
+ "metadata": {},
621
+ "outputs": [
622
+ {
623
+ "name": "stdout",
624
+ "output_type": "stream",
625
+ "text": [
626
+ "\n",
627
+ " Query: I am trying to prevent coyotes from eating the calves of my free-range cattle. What may work best and incentivize them to stay away? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\n",
628
+ "\n",
629
+ " Top 5 Retrieved Documents:\n",
630
+ "------------------------------------------------------------\n",
631
+ "\n",
632
+ "--- Document #1 ---\n",
633
+ "242 Conflict Intervention Priorities\n",
634
+ "helps foster more effective collaboration (Game et al.\n",
635
+ "2013; Lute et al. 2018). Third, both the survey results\n",
636
+ "and feedback were consistent with recent scholarship\n",
637
+ "(Redpath et al. 2017) that highlights participatory and\n",
638
+ "stakeholder-first conflict interventions as best practice\n",
639
+ "and advocates multipronged (Hazzah et al. 2014) and\n",
640
+ "adaptive management strategies (Bunnefeld et al. 2017).\n",
641
+ "Education and awareness programs were often cited in\n",
642
+ "feedback as being necessary additions to any interven-\n",
643
+ "tions. However, given the failures of many awareness-\n",
644
+ "based conservation programs (Schultz 2011), a further\n",
645
+ "exploration into why and where conservation decision\n",
646
+ "makers deem them most appropriate is important. Ap-\n",
647
+ "proaches that are specifically aimed at a particular au-\n",
648
+ "dience, such as social marketing (Salazar et al. 2018),\n",
649
+ "may be more effective than simple information provision\n",
650
+ "or—often-problematic—enforcement (Duffy et al. 2019).\n",
651
+ "However, how different interventio\n",
652
+ "\n",
653
+ "[Metadata]: {'producer': 'Acrobat Distiller 10.1.10 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': 'LaTeX with hyperref package', 'creationdate': '2020-01-16T12:33:42+05:30', 'keywords': '', 'moddate': '2025-05-27T12:12:25-07:00', 'subject': 'Conservation Biology 2020.34:232-243', 'wps-proclevel': '3', 'wps-journaldoi': '10.1111/(ISSN)1523-1739', 'author': '', 'title': 'Predicting intervention priorities for wildlife conflicts', 'wps-articledoi': '10.1111/cobi.13372', 'source': 'hwc\\\\Baynham-Herd et al. 2019.pdf', 'total_pages': 12, 'page': 10, 'page_label': '242'}\n",
654
+ "\n",
655
+ "--- Document #2 ---\n",
656
+ "Fig 1. The effects of AC programs on three metrics of black bear wariness, Whistler BC, 2007–2008. A and B show\n",
657
+ "the average observed percent change in overt reaction distance and displace ment distance among bears in the AC\n",
658
+ "Group and the Control Group. Error bars represent standard error. C shows the predicted effect of the number of AC\n",
659
+ "events conduc ted during the previous 30 days on the likeliho od that a bear will flee from research ers prior to their\n",
660
+ "beginning AC treatm ent.\n",
661
+ "https://d oi.org/10.1371/j ournal.pon e.0295989.g0 01\n",
662
+ "PLOS ONE\n",
663
+ "Aversive condition ing of conflict black bears\n",
664
+ "PLOS ONE | https://doi.or g/10.137 1/journal.po ne.02959 89 January 2, 2024 8 / 19\n",
665
+ "\n",
666
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 7, 'page_label': '8'}\n",
667
+ "\n",
668
+ "--- Document #3 ---\n",
669
+ "51] and other carnivores, such as coyotes (Canis latrans) [69, 70], African lions (Panthera leo)\n",
670
+ "[71], and wolves (Canis lupus) [72]. The relative effectiveness of these AC programs for\n",
671
+ "increasing wariness could relate to several aspects of program implementation. Because we\n",
672
+ "subjected bears to aversive stimuli as they engaged in problematic behaviour [48, 50], we\n",
673
+ "increased the likelihood that bears associated the conditioning stimulus (conflict behaviour)\n",
674
+ "with the unconditioned stimulus (pain/ stress) [38, 52]. This principle of immediacy in aver-\n",
675
+ "sive conditioning [54] is not achieved when aversive conditioning occurs upon release of a\n",
676
+ "captured bear, sometimes hours later and kilometres distant from the capture location where\n",
677
+ "conflict occurred [32]. Repetition of treatments allowed bears to generalize among experiences\n",
678
+ "instead of associating the painful stimulus with a single location or human individual, which\n",
679
+ "has been identified as important to AC programs targeting bold coyotes [69\n",
680
+ "\n",
681
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 12, 'page_label': '13'}\n",
682
+ "\n",
683
+ "--- Document #4 ---\n",
684
+ "8 \n",
685
+ " \n",
686
+ " \n",
687
+ " \n",
688
+ " \n",
689
+ " \n",
690
+ "Figure A5. Silhouette width plot of the k-medoid partitions with k = 2 to 10 used to estimate the best \n",
691
+ "number of clusters to describe livestock husbandry systems within the wolf range in northern Portugal \n",
692
+ "(see the main text for details). \n",
693
+ " \n",
694
+ "2 4 6 8 10 \n",
695
+ "0.20 0.22 0.24 0.26 0.28 0.30 0.32 \n",
696
+ "Number of clusters \n",
697
+ "Silhouette Width\n",
698
+ "\n",
699
+ "[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': 17, 'page_label': '18'}\n",
700
+ "\n",
701
+ "--- Document #5 ---\n",
702
+ "3\n",
703
+ "Vol.:(0123456789)Scientific RepoRtS | (2020) 10:15341 | https://doi.org/10.1038/s41598-020-72343-6\n",
704
+ "www.nature.com/scientificreports/\n",
705
+ "numbers increase and more bears need more food26,43,44. Hence, the effectiveness of anti-bear interventions can \n",
706
+ "be lower than expected when hungry bears become persistent and more aggressive in damaging behaviour. As \n",
707
+ "high density may lead to more bears involved in conflicts, it also could increase the demand for bear removal45 \n",
708
+ "and affect the effectiveness of removal techniques such as translocation and lethal control.\n",
709
+ "In this paper, we compiled a global database of intervention effectiveness against bears and studied how it \n",
710
+ "is related to bear species and densities, duration of intervention application, and intervention techniques. We \n",
711
+ "attempted to find and describe the most effective and the least effective interventions against bears. Further, we \n",
712
+ "tested several hypotheses: (1) lethal control and invasive management are less effective th\n",
713
+ "\n",
714
+ "[Metadata]: {'producer': 'Adobe PDF Library 15.0; modified using iText® 5.3.5 ©2000-2012 1T3XT BVBA (SPRINGER SBM; licensed version)', 'creator': 'Springer', 'creationdate': '2020-09-14T15:09:33+05:30', 'crossmarkdomains[1]': 'springer.com', 'moddate': '2020-09-14T15:58:07+02:00', 'crossmarkmajorversiondate': '2010-04-23', 'subject': 'Scientific Reports, https://doi.org/10.1038/s41598-020-72343-6', 'author': 'Igor Khorozyan', 'title': 'Variation and conservation implications of the effectiveness of anti-bear interventions', 'crossmarkdomainexclusive': 'true', 'robots': 'noindex', 'doi': '10.1038/s41598-020-72343-6', 'crossmarkdomains[2]': 'springerlink.com', 'source': 'hwc\\\\Khorozyan and Waltert 2020.pdf', 'total_pages': 9, 'page': 2, 'page_label': '3'}\n"
715
+ ]
716
+ },
717
+ {
718
+ "data": {
719
+ "text/plain": [
720
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
721
+ ]
722
+ },
723
+ "execution_count": 32,
724
+ "metadata": {},
725
+ "output_type": "execute_result"
726
+ }
727
+ ],
728
+ "source": [
729
+ "test_query = \"I am trying to prevent coyotes from eating the calves of my free-range cattle. What may work best and incentivize them to stay away? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\"\n",
730
+ "test_retriever_only(test_query, k=5)\n",
731
+ "test_retriever_only\n"
732
+ ]
733
+ },
734
+ {
735
+ "cell_type": "code",
736
+ "execution_count": 33,
737
+ "id": "64e672ff-8341-4144-a0cf-b9756661475e",
738
+ "metadata": {},
739
+ "outputs": [
740
+ {
741
+ "name": "stdout",
742
+ "output_type": "stream",
743
+ "text": [
744
+ "\n",
745
+ " Query: Deers keep destroying and takiing over our large agricultural fields. Is there anything I can try to prevent this that won’t break the bank? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\n",
746
+ "\n",
747
+ " Top 5 Retrieved Documents:\n",
748
+ "------------------------------------------------------------\n",
749
+ "\n",
750
+ "--- Document #1 ---\n",
751
+ "242 Conflict Intervention Priorities\n",
752
+ "helps foster more effective collaboration (Game et al.\n",
753
+ "2013; Lute et al. 2018). Third, both the survey results\n",
754
+ "and feedback were consistent with recent scholarship\n",
755
+ "(Redpath et al. 2017) that highlights participatory and\n",
756
+ "stakeholder-first conflict interventions as best practice\n",
757
+ "and advocates multipronged (Hazzah et al. 2014) and\n",
758
+ "adaptive management strategies (Bunnefeld et al. 2017).\n",
759
+ "Education and awareness programs were often cited in\n",
760
+ "feedback as being necessary additions to any interven-\n",
761
+ "tions. However, given the failures of many awareness-\n",
762
+ "based conservation programs (Schultz 2011), a further\n",
763
+ "exploration into why and where conservation decision\n",
764
+ "makers deem them most appropriate is important. Ap-\n",
765
+ "proaches that are specifically aimed at a particular au-\n",
766
+ "dience, such as social marketing (Salazar et al. 2018),\n",
767
+ "may be more effective than simple information provision\n",
768
+ "or—often-problematic—enforcement (Duffy et al. 2019).\n",
769
+ "However, how different interventio\n",
770
+ "\n",
771
+ "[Metadata]: {'producer': 'Acrobat Distiller 10.1.10 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': 'LaTeX with hyperref package', 'creationdate': '2020-01-16T12:33:42+05:30', 'keywords': '', 'moddate': '2025-05-27T12:12:25-07:00', 'subject': 'Conservation Biology 2020.34:232-243', 'wps-proclevel': '3', 'wps-journaldoi': '10.1111/(ISSN)1523-1739', 'author': '', 'title': 'Predicting intervention priorities for wildlife conflicts', 'wps-articledoi': '10.1111/cobi.13372', 'source': 'hwc\\\\Baynham-Herd et al. 2019.pdf', 'total_pages': 12, 'page': 10, 'page_label': '242'}\n",
772
+ "\n",
773
+ "--- Document #2 ---\n",
774
+ "8 \n",
775
+ " \n",
776
+ " \n",
777
+ " \n",
778
+ " \n",
779
+ " \n",
780
+ "Figure A5. Silhouette width plot of the k-medoid partitions with k = 2 to 10 used to estimate the best \n",
781
+ "number of clusters to describe livestock husbandry systems within the wolf range in northern Portugal \n",
782
+ "(see the main text for details). \n",
783
+ " \n",
784
+ "2 4 6 8 10 \n",
785
+ "0.20 0.22 0.24 0.26 0.28 0.30 0.32 \n",
786
+ "Number of clusters \n",
787
+ "Silhouette Width\n",
788
+ "\n",
789
+ "[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': 17, 'page_label': '18'}\n",
790
+ "\n",
791
+ "--- Document #3 ---\n",
792
+ "Fig 1. The effects of AC programs on three metrics of black bear wariness, Whistler BC, 2007–2008. A and B show\n",
793
+ "the average observed percent change in overt reaction distance and displace ment distance among bears in the AC\n",
794
+ "Group and the Control Group. Error bars represent standard error. C shows the predicted effect of the number of AC\n",
795
+ "events conduc ted during the previous 30 days on the likeliho od that a bear will flee from research ers prior to their\n",
796
+ "beginning AC treatm ent.\n",
797
+ "https://d oi.org/10.1371/j ournal.pon e.0295989.g0 01\n",
798
+ "PLOS ONE\n",
799
+ "Aversive condition ing of conflict black bears\n",
800
+ "PLOS ONE | https://doi.or g/10.137 1/journal.po ne.02959 89 January 2, 2024 8 / 19\n",
801
+ "\n",
802
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 7, 'page_label': '8'}\n",
803
+ "\n",
804
+ "--- Document #4 ---\n",
805
+ "3\n",
806
+ "Vol.:(0123456789)Scientific RepoRtS | (2020) 10:15341 | https://doi.org/10.1038/s41598-020-72343-6\n",
807
+ "www.nature.com/scientificreports/\n",
808
+ "numbers increase and more bears need more food26,43,44. Hence, the effectiveness of anti-bear interventions can \n",
809
+ "be lower than expected when hungry bears become persistent and more aggressive in damaging behaviour. As \n",
810
+ "high density may lead to more bears involved in conflicts, it also could increase the demand for bear removal45 \n",
811
+ "and affect the effectiveness of removal techniques such as translocation and lethal control.\n",
812
+ "In this paper, we compiled a global database of intervention effectiveness against bears and studied how it \n",
813
+ "is related to bear species and densities, duration of intervention application, and intervention techniques. We \n",
814
+ "attempted to find and describe the most effective and the least effective interventions against bears. Further, we \n",
815
+ "tested several hypotheses: (1) lethal control and invasive management are less effective th\n",
816
+ "\n",
817
+ "[Metadata]: {'producer': 'Adobe PDF Library 15.0; modified using iText® 5.3.5 ©2000-2012 1T3XT BVBA (SPRINGER SBM; licensed version)', 'creator': 'Springer', 'creationdate': '2020-09-14T15:09:33+05:30', 'crossmarkdomains[1]': 'springer.com', 'moddate': '2020-09-14T15:58:07+02:00', 'crossmarkmajorversiondate': '2010-04-23', 'subject': 'Scientific Reports, https://doi.org/10.1038/s41598-020-72343-6', 'author': 'Igor Khorozyan', 'title': 'Variation and conservation implications of the effectiveness of anti-bear interventions', 'crossmarkdomainexclusive': 'true', 'robots': 'noindex', 'doi': '10.1038/s41598-020-72343-6', 'crossmarkdomains[2]': 'springerlink.com', 'source': 'hwc\\\\Khorozyan and Waltert 2020.pdf', 'total_pages': 9, 'page': 2, 'page_label': '3'}\n",
818
+ "\n",
819
+ "--- Document #5 ---\n",
820
+ "51] and other carnivores, such as coyotes (Canis latrans) [69, 70], African lions (Panthera leo)\n",
821
+ "[71], and wolves (Canis lupus) [72]. The relative effectiveness of these AC programs for\n",
822
+ "increasing wariness could relate to several aspects of program implementation. Because we\n",
823
+ "subjected bears to aversive stimuli as they engaged in problematic behaviour [48, 50], we\n",
824
+ "increased the likelihood that bears associated the conditioning stimulus (conflict behaviour)\n",
825
+ "with the unconditioned stimulus (pain/ stress) [38, 52]. This principle of immediacy in aver-\n",
826
+ "sive conditioning [54] is not achieved when aversive conditioning occurs upon release of a\n",
827
+ "captured bear, sometimes hours later and kilometres distant from the capture location where\n",
828
+ "conflict occurred [32]. Repetition of treatments allowed bears to generalize among experiences\n",
829
+ "instead of associating the painful stimulus with a single location or human individual, which\n",
830
+ "has been identified as important to AC programs targeting bold coyotes [69\n",
831
+ "\n",
832
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 12, 'page_label': '13'}\n"
833
+ ]
834
+ },
835
+ {
836
+ "data": {
837
+ "text/plain": [
838
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
839
+ ]
840
+ },
841
+ "execution_count": 33,
842
+ "metadata": {},
843
+ "output_type": "execute_result"
844
+ }
845
+ ],
846
+ "source": [
847
+ "test_query = \"Deers keep destroying and takiing over our large agricultural fields. Is there anything I can try to prevent this that won’t break the bank? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\"\n",
848
+ "test_retriever_only(test_query, k=5)\n",
849
+ "test_retriever_only"
850
+ ]
851
+ },
852
+ {
853
+ "cell_type": "code",
854
+ "execution_count": 34,
855
+ "id": "02565fb4-321b-4cfc-be06-7ffaf1f7f37e",
856
+ "metadata": {},
857
+ "outputs": [
858
+ {
859
+ "name": "stdout",
860
+ "output_type": "stream",
861
+ "text": [
862
+ "\n",
863
+ " Query: We live in a suburb and bears sometimes come into our town to eat from our fruit trees and trash. What are the best ways for us to prevent this as a community without removing our fruit trees? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\n",
864
+ "\n",
865
+ " Top 5 Retrieved Documents:\n",
866
+ "------------------------------------------------------------\n",
867
+ "\n",
868
+ "--- Document #1 ---\n",
869
+ "242 Conflict Intervention Priorities\n",
870
+ "helps foster more effective collaboration (Game et al.\n",
871
+ "2013; Lute et al. 2018). Third, both the survey results\n",
872
+ "and feedback were consistent with recent scholarship\n",
873
+ "(Redpath et al. 2017) that highlights participatory and\n",
874
+ "stakeholder-first conflict interventions as best practice\n",
875
+ "and advocates multipronged (Hazzah et al. 2014) and\n",
876
+ "adaptive management strategies (Bunnefeld et al. 2017).\n",
877
+ "Education and awareness programs were often cited in\n",
878
+ "feedback as being necessary additions to any interven-\n",
879
+ "tions. However, given the failures of many awareness-\n",
880
+ "based conservation programs (Schultz 2011), a further\n",
881
+ "exploration into why and where conservation decision\n",
882
+ "makers deem them most appropriate is important. Ap-\n",
883
+ "proaches that are specifically aimed at a particular au-\n",
884
+ "dience, such as social marketing (Salazar et al. 2018),\n",
885
+ "may be more effective than simple information provision\n",
886
+ "or—often-problematic—enforcement (Duffy et al. 2019).\n",
887
+ "However, how different interventio\n",
888
+ "\n",
889
+ "[Metadata]: {'producer': 'Acrobat Distiller 10.1.10 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': 'LaTeX with hyperref package', 'creationdate': '2020-01-16T12:33:42+05:30', 'keywords': '', 'moddate': '2025-05-27T12:12:25-07:00', 'subject': 'Conservation Biology 2020.34:232-243', 'wps-proclevel': '3', 'wps-journaldoi': '10.1111/(ISSN)1523-1739', 'author': '', 'title': 'Predicting intervention priorities for wildlife conflicts', 'wps-articledoi': '10.1111/cobi.13372', 'source': 'hwc\\\\Baynham-Herd et al. 2019.pdf', 'total_pages': 12, 'page': 10, 'page_label': '242'}\n",
890
+ "\n",
891
+ "--- Document #2 ---\n",
892
+ "8 \n",
893
+ " \n",
894
+ " \n",
895
+ " \n",
896
+ " \n",
897
+ " \n",
898
+ "Figure A5. Silhouette width plot of the k-medoid partitions with k = 2 to 10 used to estimate the best \n",
899
+ "number of clusters to describe livestock husbandry systems within the wolf range in northern Portugal \n",
900
+ "(see the main text for details). \n",
901
+ " \n",
902
+ "2 4 6 8 10 \n",
903
+ "0.20 0.22 0.24 0.26 0.28 0.30 0.32 \n",
904
+ "Number of clusters \n",
905
+ "Silhouette Width\n",
906
+ "\n",
907
+ "[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': 17, 'page_label': '18'}\n",
908
+ "\n",
909
+ "--- Document #3 ---\n",
910
+ "51] and other carnivores, such as coyotes (Canis latrans) [69, 70], African lions (Panthera leo)\n",
911
+ "[71], and wolves (Canis lupus) [72]. The relative effectiveness of these AC programs for\n",
912
+ "increasing wariness could relate to several aspects of program implementation. Because we\n",
913
+ "subjected bears to aversive stimuli as they engaged in problematic behaviour [48, 50], we\n",
914
+ "increased the likelihood that bears associated the conditioning stimulus (conflict behaviour)\n",
915
+ "with the unconditioned stimulus (pain/ stress) [38, 52]. This principle of immediacy in aver-\n",
916
+ "sive conditioning [54] is not achieved when aversive conditioning occurs upon release of a\n",
917
+ "captured bear, sometimes hours later and kilometres distant from the capture location where\n",
918
+ "conflict occurred [32]. Repetition of treatments allowed bears to generalize among experiences\n",
919
+ "instead of associating the painful stimulus with a single location or human individual, which\n",
920
+ "has been identified as important to AC programs targeting bold coyotes [69\n",
921
+ "\n",
922
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 12, 'page_label': '13'}\n",
923
+ "\n",
924
+ "--- Document #4 ---\n",
925
+ "Fig 1. The effects of AC programs on three metrics of black bear wariness, Whistler BC, 2007–2008. A and B show\n",
926
+ "the average observed percent change in overt reaction distance and displace ment distance among bears in the AC\n",
927
+ "Group and the Control Group. Error bars represent standard error. C shows the predicted effect of the number of AC\n",
928
+ "events conduc ted during the previous 30 days on the likeliho od that a bear will flee from research ers prior to their\n",
929
+ "beginning AC treatm ent.\n",
930
+ "https://d oi.org/10.1371/j ournal.pon e.0295989.g0 01\n",
931
+ "PLOS ONE\n",
932
+ "Aversive condition ing of conflict black bears\n",
933
+ "PLOS ONE | https://doi.or g/10.137 1/journal.po ne.02959 89 January 2, 2024 8 / 19\n",
934
+ "\n",
935
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 7, 'page_label': '8'}\n",
936
+ "\n",
937
+ "--- Document #5 ---\n",
938
+ "* Correspondence: B. F. Blackwell, U.S. Department of Agriculture, Animal and\n",
939
+ "Plant Health Inspection Service, Wildlife Services, National Wildlife Research\n",
940
+ "Center, Ohio Field Station, Sandusky, OH, 44870, U.S.A.\n",
941
+ "E-mail address: bradley.f.blackwell@aphis.usda.gov (B. F. Blackwell).\n",
942
+ "Contents lists available atScienceDirect\n",
943
+ "Animal Behaviour\n",
944
+ "journal homepage: www.elsevier.com/locate/anbehav\n",
945
+ "http://dx.doi.org/10.1016/j.anbehav.2016.07.013\n",
946
+ "0003-3472/Published by Elsevier Ltd on behalf of The Association for the Study of Animal Behaviour.\n",
947
+ "Animal Behaviour 120 (2016) 245e254\n",
948
+ "SPECIAL ISSUE: CONSERVATION BEHAVIOUR\n",
949
+ "\n",
950
+ "[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': 0, 'page_label': '245'}\n"
951
+ ]
952
+ },
953
+ {
954
+ "data": {
955
+ "text/plain": [
956
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
957
+ ]
958
+ },
959
+ "execution_count": 34,
960
+ "metadata": {},
961
+ "output_type": "execute_result"
962
+ }
963
+ ],
964
+ "source": [
965
+ "test_query = \"We live in a suburb and bears sometimes come into our town to eat from our fruit trees and trash. What are the best ways for us to prevent this as a community without removing our fruit trees? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\"\n",
966
+ "test_retriever_only(test_query, k=5)\n",
967
+ "test_retriever_only"
968
+ ]
969
+ },
970
+ {
971
+ "cell_type": "code",
972
+ "execution_count": 35,
973
+ "id": "ed58ac9d-edda-483b-b617-1e8bed445fe7",
974
+ "metadata": {},
975
+ "outputs": [
976
+ {
977
+ "name": "stdout",
978
+ "output_type": "stream",
979
+ "text": [
980
+ "\n",
981
+ " Query: If we live in an area with a lot of wolves, what cattle husbandry strategies should I employ to prevent any sort of wildlife-human conflict? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\n",
982
+ "\n",
983
+ " Top 5 Retrieved Documents:\n",
984
+ "------------------------------------------------------------\n",
985
+ "\n",
986
+ "--- Document #1 ---\n",
987
+ "242 Conflict Intervention Priorities\n",
988
+ "helps foster more effective collaboration (Game et al.\n",
989
+ "2013; Lute et al. 2018). Third, both the survey results\n",
990
+ "and feedback were consistent with recent scholarship\n",
991
+ "(Redpath et al. 2017) that highlights participatory and\n",
992
+ "stakeholder-first conflict interventions as best practice\n",
993
+ "and advocates multipronged (Hazzah et al. 2014) and\n",
994
+ "adaptive management strategies (Bunnefeld et al. 2017).\n",
995
+ "Education and awareness programs were often cited in\n",
996
+ "feedback as being necessary additions to any interven-\n",
997
+ "tions. However, given the failures of many awareness-\n",
998
+ "based conservation programs (Schultz 2011), a further\n",
999
+ "exploration into why and where conservation decision\n",
1000
+ "makers deem them most appropriate is important. Ap-\n",
1001
+ "proaches that are specifically aimed at a particular au-\n",
1002
+ "dience, such as social marketing (Salazar et al. 2018),\n",
1003
+ "may be more effective than simple information provision\n",
1004
+ "or—often-problematic—enforcement (Duffy et al. 2019).\n",
1005
+ "However, how different interventio\n",
1006
+ "\n",
1007
+ "[Metadata]: {'producer': 'Acrobat Distiller 10.1.10 (Windows); modified using iText 4.2.0 by 1T3XT', 'creator': 'LaTeX with hyperref package', 'creationdate': '2020-01-16T12:33:42+05:30', 'keywords': '', 'moddate': '2025-05-27T12:12:25-07:00', 'subject': 'Conservation Biology 2020.34:232-243', 'wps-proclevel': '3', 'wps-journaldoi': '10.1111/(ISSN)1523-1739', 'author': '', 'title': 'Predicting intervention priorities for wildlife conflicts', 'wps-articledoi': '10.1111/cobi.13372', 'source': 'hwc\\\\Baynham-Herd et al. 2019.pdf', 'total_pages': 12, 'page': 10, 'page_label': '242'}\n",
1008
+ "\n",
1009
+ "--- Document #2 ---\n",
1010
+ "Fig 1. The effects of AC programs on three metrics of black bear wariness, Whistler BC, 2007–2008. A and B show\n",
1011
+ "the average observed percent change in overt reaction distance and displace ment distance among bears in the AC\n",
1012
+ "Group and the Control Group. Error bars represent standard error. C shows the predicted effect of the number of AC\n",
1013
+ "events conduc ted during the previous 30 days on the likeliho od that a bear will flee from research ers prior to their\n",
1014
+ "beginning AC treatm ent.\n",
1015
+ "https://d oi.org/10.1371/j ournal.pon e.0295989.g0 01\n",
1016
+ "PLOS ONE\n",
1017
+ "Aversive condition ing of conflict black bears\n",
1018
+ "PLOS ONE | https://doi.or g/10.137 1/journal.po ne.02959 89 January 2, 2024 8 / 19\n",
1019
+ "\n",
1020
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 7, 'page_label': '8'}\n",
1021
+ "\n",
1022
+ "--- Document #3 ---\n",
1023
+ "51] and other carnivores, such as coyotes (Canis latrans) [69, 70], African lions (Panthera leo)\n",
1024
+ "[71], and wolves (Canis lupus) [72]. The relative effectiveness of these AC programs for\n",
1025
+ "increasing wariness could relate to several aspects of program implementation. Because we\n",
1026
+ "subjected bears to aversive stimuli as they engaged in problematic behaviour [48, 50], we\n",
1027
+ "increased the likelihood that bears associated the conditioning stimulus (conflict behaviour)\n",
1028
+ "with the unconditioned stimulus (pain/ stress) [38, 52]. This principle of immediacy in aver-\n",
1029
+ "sive conditioning [54] is not achieved when aversive conditioning occurs upon release of a\n",
1030
+ "captured bear, sometimes hours later and kilometres distant from the capture location where\n",
1031
+ "conflict occurred [32]. Repetition of treatments allowed bears to generalize among experiences\n",
1032
+ "instead of associating the painful stimulus with a single location or human individual, which\n",
1033
+ "has been identified as important to AC programs targeting bold coyotes [69\n",
1034
+ "\n",
1035
+ "[Metadata]: {'producer': 'PDFlib+PDI 9.3.1p2 (C++/Win64)', 'creator': 'PTC Arbortext Layout Developer 12.1.6180/W-x64', 'creationdate': '2023-12-25T16:46:13+05:30', 'title': 'Aversive conditioning increases short-term wariness but does not change habitat use in black bears associated with conflict', 'epsprocessor': 'PStill version 1.84.42', 'author': 'Lori Homstol, Sage Raymond, Claire Edwards, Anthony N. Hamilton, Colleen Cassady St. Clair', 'moddate': '2023-12-25T16:46:13+05:30', 'source': 'hwc\\\\Homstol et al. 2024.pdf', 'total_pages': 19, 'page': 12, 'page_label': '13'}\n",
1036
+ "\n",
1037
+ "--- Document #4 ---\n",
1038
+ "3\n",
1039
+ "Vol.:(0123456789)Scientific RepoRtS | (2020) 10:15341 | https://doi.org/10.1038/s41598-020-72343-6\n",
1040
+ "www.nature.com/scientificreports/\n",
1041
+ "numbers increase and more bears need more food26,43,44. Hence, the effectiveness of anti-bear interventions can \n",
1042
+ "be lower than expected when hungry bears become persistent and more aggressive in damaging behaviour. As \n",
1043
+ "high density may lead to more bears involved in conflicts, it also could increase the demand for bear removal45 \n",
1044
+ "and affect the effectiveness of removal techniques such as translocation and lethal control.\n",
1045
+ "In this paper, we compiled a global database of intervention effectiveness against bears and studied how it \n",
1046
+ "is related to bear species and densities, duration of intervention application, and intervention techniques. We \n",
1047
+ "attempted to find and describe the most effective and the least effective interventions against bears. Further, we \n",
1048
+ "tested several hypotheses: (1) lethal control and invasive management are less effective th\n",
1049
+ "\n",
1050
+ "[Metadata]: {'producer': 'Adobe PDF Library 15.0; modified using iText® 5.3.5 ©2000-2012 1T3XT BVBA (SPRINGER SBM; licensed version)', 'creator': 'Springer', 'creationdate': '2020-09-14T15:09:33+05:30', 'crossmarkdomains[1]': 'springer.com', 'moddate': '2020-09-14T15:58:07+02:00', 'crossmarkmajorversiondate': '2010-04-23', 'subject': 'Scientific Reports, https://doi.org/10.1038/s41598-020-72343-6', 'author': 'Igor Khorozyan', 'title': 'Variation and conservation implications of the effectiveness of anti-bear interventions', 'crossmarkdomainexclusive': 'true', 'robots': 'noindex', 'doi': '10.1038/s41598-020-72343-6', 'crossmarkdomains[2]': 'springerlink.com', 'source': 'hwc\\\\Khorozyan and Waltert 2020.pdf', 'total_pages': 9, 'page': 2, 'page_label': '3'}\n",
1051
+ "\n",
1052
+ "--- Document #5 ---\n",
1053
+ "8 \n",
1054
+ " \n",
1055
+ " \n",
1056
+ " \n",
1057
+ " \n",
1058
+ " \n",
1059
+ "Figure A5. Silhouette width plot of the k-medoid partitions with k = 2 to 10 used to estimate the best \n",
1060
+ "number of clusters to describe livestock husbandry systems within the wolf range in northern Portugal \n",
1061
+ "(see the main text for details). \n",
1062
+ " \n",
1063
+ "2 4 6 8 10 \n",
1064
+ "0.20 0.22 0.24 0.26 0.28 0.30 0.32 \n",
1065
+ "Number of clusters \n",
1066
+ "Silhouette Width\n",
1067
+ "\n",
1068
+ "[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': 17, 'page_label': '18'}\n"
1069
+ ]
1070
+ },
1071
+ {
1072
+ "data": {
1073
+ "text/plain": [
1074
+ "<function __main__.test_retriever_only(query: str, k: int = 5)>"
1075
+ ]
1076
+ },
1077
+ "execution_count": 35,
1078
+ "metadata": {},
1079
+ "output_type": "execute_result"
1080
+ }
1081
+ ],
1082
+ "source": [
1083
+ "test_query = \"If we live in an area with a lot of wolves, what cattle husbandry strategies should I employ to prevent any sort of wildlife-human conflict? Can you check these pdfs to see which ones might help? https://minio.carlboettiger.info/public-data/hwc.zip\"\n",
1084
+ "test_retriever_only(test_query, k=5)\n",
1085
+ "test_retriever_only"
1086
+ ]
1087
+ }
1088
+ ],
1089
+ "metadata": {
1090
+ "kernelspec": {
1091
+ "display_name": "Python 3 (ipykernel)",
1092
+ "language": "python",
1093
+ "name": "python3"
1094
+ },
1095
+ "language_info": {
1096
+ "codemirror_mode": {
1097
+ "name": "ipython",
1098
+ "version": 3
1099
+ },
1100
+ "file_extension": ".py",
1101
+ "mimetype": "text/x-python",
1102
+ "name": "python",
1103
+ "nbconvert_exporter": "python",
1104
+ "pygments_lexer": "ipython3",
1105
+ "version": "3.12.4"
1106
+ }
1107
+ },
1108
+ "nbformat": 4,
1109
+ "nbformat_minor": 5
1110
+ }