Skip to content

Commit 0613b83

Browse files
test notebook fix?
1 parent dc8a45a commit 0613b83

File tree

1 file changed

+79
-72
lines changed

1 file changed

+79
-72
lines changed

docs/user_guide/vectorizers_04.ipynb

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -497,76 +497,76 @@
497497
]
498498
},
499499
{
500-
"cell_type": "markdown",
501-
"metadata": {},
502-
"source": [
503-
"### VoyageAI\n",
504-
"\n",
505-
"[VoyageAI](https://dash.voyageai.com/) allows you to implement language AI into your product. The `VoyageAITextVectorizer` makes it simple to use RedisVL with the embeddings models at VoyageAI. For this you will need to install `voyageai`.\n",
506-
"\n",
507-
"```bash\n",
508-
"pip install voyageai\n",
509-
"```"
510-
]
511-
},
512-
{
513-
"cell_type": "code",
514-
"execution_count": 11,
515-
"metadata": {},
516-
"outputs": [],
517-
"source": [
518-
"import getpass\n",
519-
"# setup the API Key\n",
520-
"api_key = os.environ.get(\"VOYAGE_API_KEY\") or getpass.getpass(\"Enter your VoyageAI API key: \")"
521-
]
522-
},
523-
{
524-
"cell_type": "markdown",
525-
"metadata": {},
526-
"source": [
527-
"\n",
528-
"Special attention needs to be paid to the `input_type` parameter for each `embed` call. For example, for embedding \n",
529-
"queries, you should set `input_type='query'`; for embedding documents, set `input_type='document'`. See\n",
530-
"more information [here](https://docs.voyageai.com/docs/embeddings)"
531-
]
532-
},
533-
{
534-
"cell_type": "code",
535-
"execution_count": 12,
536-
"metadata": {},
537-
"outputs": [
538-
{
539-
"name": "stdout",
540-
"output_type": "stream",
541-
"text": [
542-
"Vector dimensions: 1024\n",
543-
"[0.015814896672964096, 0.046988241374492645, -0.00518248463049531, -0.05383478105068207, -0.015586535446345806, -0.0837097093462944, 0.03744547441601753, -0.007797810714691877, 0.00717928446829319, 0.06857716292142868]\n",
544-
"Vector dimensions: 1024\n",
545-
"[0.006725038401782513, 0.01441393606364727, -0.030212024226784706, -0.06782275438308716, -0.021446991711854935, -0.07667966187000275, 0.01804908737540245, -0.015767497941851616, -0.02152789570391178, 0.049741245806217194]\n"
546-
]
547-
}
548-
],
549-
"source": [
550-
"from redisvl.utils.vectorize import VoyageAITextVectorizer\n",
551-
"\n",
552-
"# create a vectorizer\n",
553-
"vo = VoyageAITextVectorizer(\n",
554-
" model=\"voyage-law-2\", # Please check the available models at https://docs.voyageai.com/docs/embeddings\n",
555-
" api_config={\"api_key\": api_key},\n",
556-
")\n",
557-
"\n",
558-
"# embed a search query\n",
559-
"test = vo.embed(\"This is a test sentence.\", input_type='query')\n",
560-
"print(\"Vector dimensions: \", len(test))\n",
561-
"print(test[:10])\n",
562-
"\n",
563-
"# embed a document\n",
564-
"test = vo.embed(\"This is a test sentence.\", input_type='document')\n",
565-
"print(\"Vector dimensions: \", len(test))\n",
566-
"print(test[:10])"
567-
]
568-
},
569-
{
500+
"cell_type": "markdown",
501+
"metadata": {},
502+
"source": [
503+
"### VoyageAI\n",
504+
"\n",
505+
"[VoyageAI](https://dash.voyageai.com/) allows you to implement language AI into your product. The `VoyageAITextVectorizer` makes it simple to use RedisVL with the embeddings models at VoyageAI. For this you will need to install `voyageai`.\n",
506+
"\n",
507+
"```bash\n",
508+
"pip install voyageai\n",
509+
"```"
510+
]
511+
},
512+
{
513+
"cell_type": "code",
514+
"execution_count": 11,
515+
"metadata": {},
516+
"outputs": [],
517+
"source": [
518+
"import getpass\n",
519+
"# setup the API Key\n",
520+
"api_key = os.environ.get(\"VOYAGE_API_KEY\") or getpass.getpass(\"Enter your VoyageAI API key: \")"
521+
]
522+
},
523+
{
524+
"cell_type": "markdown",
525+
"metadata": {},
526+
"source": [
527+
"\n",
528+
"Special attention needs to be paid to the `input_type` parameter for each `embed` call. For example, for embedding \n",
529+
"queries, you should set `input_type='query'`; for embedding documents, set `input_type='document'`. See\n",
530+
"more information [here](https://docs.voyageai.com/docs/embeddings)"
531+
]
532+
},
533+
{
534+
"cell_type": "code",
535+
"execution_count": 12,
536+
"metadata": {},
537+
"outputs": [
538+
{
539+
"name": "stdout",
540+
"output_type": "stream",
541+
"text": [
542+
"Vector dimensions: 1024\n",
543+
"[0.015814896672964096, 0.046988241374492645, -0.00518248463049531, -0.05383478105068207, -0.015586535446345806, -0.0837097093462944, 0.03744547441601753, -0.007797810714691877, 0.00717928446829319, 0.06857716292142868]\n",
544+
"Vector dimensions: 1024\n",
545+
"[0.006725038401782513, 0.01441393606364727, -0.030212024226784706, -0.06782275438308716, -0.021446991711854935, -0.07667966187000275, 0.01804908737540245, -0.015767497941851616, -0.02152789570391178, 0.049741245806217194]\n"
546+
]
547+
}
548+
],
549+
"source": [
550+
"from redisvl.utils.vectorize import VoyageAITextVectorizer\n",
551+
"\n",
552+
"# create a vectorizer\n",
553+
"vo = VoyageAITextVectorizer(\n",
554+
" model=\"voyage-law-2\", # Please check the available models at https://docs.voyageai.com/docs/embeddings\n",
555+
" api_config={\"api_key\": api_key},\n",
556+
")\n",
557+
"\n",
558+
"# embed a search query\n",
559+
"test = vo.embed(\"This is a test sentence.\", input_type='query')\n",
560+
"print(\"Vector dimensions: \", len(test))\n",
561+
"print(test[:10])\n",
562+
"\n",
563+
"# embed a document\n",
564+
"test = vo.embed(\"This is a test sentence.\", input_type='document')\n",
565+
"print(\"Vector dimensions: \", len(test))\n",
566+
"print(test[:10])"
567+
]
568+
},
569+
{
570570
"cell_type": "markdown",
571571
"metadata": {},
572572
"source": [
@@ -831,6 +831,13 @@
831831
"!rvl index listall"
832832
]
833833
},
834+
{
835+
"cell_type": "markdown",
836+
"metadata": {},
837+
"source": [
838+
"Loading data to RedisVL is easy. It expects a list of dictionaries. The vector is stored as bytes."
839+
]
840+
},
834841
{
835842
"cell_type": "code",
836843
"execution_count": null,
@@ -850,10 +857,10 @@
850857
}
851858
],
852859
"source": [
853-
"# load expects an iterable of dictionaries where\n",
854-
"# the vector is stored as a bytes buffer\n",
855860
"from redisvl.redis.utils import array_to_buffer\n",
856861
"\n",
862+
"embeddings = hf.embed_many(sentences)\n",
863+
"\n",
857864
"data = [{\"text\": t,\n",
858865
" \"embedding\": array_to_buffer(v, dtype=\"float32\")}\n",
859866
" for t, v in zip(sentences, embeddings)]\n",

0 commit comments

Comments
 (0)