1 00:00:00,700 --> 00:00:04,890 In this video, we will discuss namespaces, which are an important 2 00:00:04,900 --> 00:00:07,270 concept when working with PineCon. 3 00:00:08,600 --> 00:00:11,310 PineCon allows you to partition the 4 00:00:11,320 --> 00:00:13,890 vectors in an index into namespaces. 5 00:00:16,600 --> 00:00:19,470 Queries and other operations are then 6 00:00:19,480 --> 00:00:24,850 scoped to a specific namespace, allowing different requests to search different 7 00:00:24,860 --> 00:00:26,650 subsets of your index. 8 00:00:26,660 --> 00:00:30,310 Imagine you are dealing with news 9 00:00:30,320 --> 00:00:35,930 articles, you might want to create a namespace for indexing articles by 10 00:00:35,940 --> 00:00:40,510 content and another for indexing articles by title. 11 00:00:41,960 --> 00:00:45,190 Here is the key information about namespaces. 12 00:00:46,460 --> 00:00:49,430 Every index consists of one or more 13 00:00:49,440 --> 00:00:55,070 namespaces, each vector exists in exactly one namespace. 14 00:00:55,800 --> 00:01:02,910 Namespaces are uniquely identified by a namespace name and the default namespace 15 00:01:02,920 --> 00:01:10,310 is represented by the empty string and is used if no specific namespace is specified. 16 00:01:11,360 --> 00:01:16,910 Remember that all the operations you learned about in the previous video will 17 00:01:16,920 --> 00:01:22,330 be constrained to a namespace if we include the namespace argument in each method. 18 00:01:23,660 --> 00:01:25,830 Let s see some examples. 19 00:01:27,280 --> 00:01:29,910 I am starting with an empty index. 20 00:01:31,080 --> 00:01:37,430 I have just removed and recreated the index, it is empty. 21 00:01:38,140 --> 00:01:42,990 I ll work with the index called LangChain, so I am selecting it. 22 00:01:43,800 --> 00:01:48,150 index equals PC .index of LangChain. 23 00:01:54,590 --> 00:01:58,760 Now I am creating a namespace, namespaces 24 00:01:58,770 --> 00:02:03,860 are automatically created the first time they are used to upstart records. 25 00:02:05,650 --> 00:02:12,000 From the previous examples, I am copy -pasting the code that inserts 5 random 26 00:02:12,010 --> 00:02:13,760 vectors into the index. 27 00:02:15,170 --> 00:02:18,780 If I run this code, the vectors will be 28 00:02:18,790 --> 00:02:24,600 inserted in the default namespace which is represented by the empty string, I am 29 00:02:24,610 --> 00:02:25,100 running it. 30 00:02:26,390 --> 00:02:29,820 Now, I will add another 3 random vectors 31 00:02:29,830 --> 00:02:32,880 in a namespace called firstNamespace. 32 00:02:33,310 --> 00:02:35,160 I am copy -pasting this code. 33 00:02:36,690 --> 00:02:46,390 I will insert 3 vectors in the namespace, their IDs will be x, y and z. 34 00:02:47,180 --> 00:02:58,770 And I am adding a second argument to the upstart method, namespace equals firstNamespace. 35 00:03:00,460 --> 00:03:06,770 If the namespace does not exist, it is created implicitly, I am running it. 36 00:03:09,740 --> 00:03:12,450 Just like that, you can create more than one namespace. 37 00:03:15,080 --> 00:03:20,780 Here, I am creating another namespace called secondNamespace and adding 2 38 00:03:20,790 --> 00:03:22,140 random vectors to it. 39 00:03:32,050 --> 00:03:34,500 I am fetching index statistics, 40 00:03:40,430 --> 00:03:47,440 currently, there are 3 namespaces in the index, the default namespace empty string 41 00:03:47,450 --> 00:03:55,420 contains 5 vectors, the firstNamespace contains 3 vectors and the 42 00:03:55,430 --> 00:04:03,520 secondNamespace contains 2 vectors, there are a total of 10 vectors in the index. 43 00:04:04,860 --> 00:04:11,120 All vector operations apply to a single namespace except describe index statistics. 44 00:04:12,040 --> 00:04:21,560 I am fetching the vector with the ID x, index .h, IDs equals x. 45 00:04:22,170 --> 00:04:27,900 If I run this code, it will return an empty vector because it queries the 46 00:04:27,910 --> 00:04:31,820 default namespace and there is no vector with this ID. 47 00:04:32,730 --> 00:04:40,220 The vector with the ID x is in the firstNamespace and I have to specify it explicitly. 48 00:04:41,350 --> 00:04:52,350 I am adding namespace equals firstNamespace and I have got the vector, 49 00:04:55,930 --> 00:05:00,920 that applies to any other operation, if you try to delete a vector you will have 50 00:05:00,930 --> 00:05:10,000 to specify the namespace to which it belongs, index .delete of IDs equals x 51 00:05:12,410 --> 00:05:26,990 and the namespace equals firstNamespace, I am running it, it was deleted so the 52 00:05:27,000 --> 00:05:29,690 fetch operation returns an empty vector. 53 00:05:31,200 --> 00:05:33,910 To delete all records from a namespace, 54 00:05:34,320 --> 00:05:39,890 specify the deleteAll arguments to index .delete and provide a namespace argument, 55 00:05:40,580 --> 00:05:49,870 index .delete of deleteAll equals true and the namespace equals firstNamespace, 56 00:05:54,430 --> 00:06:00,520 note that deleting all records from a namespace also deletes the namespace 57 00:06:00,530 --> 00:06:13,890 itself, I have deleted it, I am calling index .describeIndexStacks again, there 58 00:06:13,900 --> 00:06:21,970 is no namespace called firstNamespace anymore, we have covered the concept of 59 00:06:21,980 --> 00:06:27,670 namespaces, now let s take a break, in the upcoming section we ll consolidate 60 00:06:27,680 --> 00:06:34,190 what we ve learned so far and dive into developing an app using LLMs, embeddings, 61 00:06:34,580 --> 00:06:40,570 vectors and more, in the next video we ll explore splitting and embedding text 62 00:06:40,580 --> 00:06:42,530 using Langchain, stay tuned!