In this video, we will discuss namespaces, which are an important
concept when working with PineCon.
PineCon allows you to partition the
vectors in an index into namespaces.
Queries and other operations are then
scoped to a specific namespace, allowing different requests to search different
subsets of your index.
Imagine you are dealing with news
articles, you might want to create a namespace for indexing articles by
content and another for indexing articles by title.
Here is the key information about namespaces.
Every index consists of one or more
namespaces, each vector exists in exactly one namespace.
Namespaces are uniquely identified by a namespace name and the default namespace
is represented by the empty string and is used if no specific namespace is specified.
Remember that all the operations you learned about in the previous video will
be constrained to a namespace if we include the namespace argument in each method.
Let s see some examples.
I am starting with an empty index.
I have just removed and recreated the index, it is empty.
I ll work with the index called LangChain, so I am selecting it.
index equals PC .index of LangChain.
Now I am creating a namespace, namespaces
are automatically created the first time they are used to upstart records.
From the previous examples, I am copy -pasting the code that inserts 5 random
vectors into the index.
If I run this code, the vectors will be
inserted in the default namespace which is represented by the empty string, I am
running it.
Now, I will add another 3 random vectors
in a namespace called firstNamespace.
I am copy -pasting this code.
I will insert 3 vectors in the namespace, their IDs will be x, y and z.
And I am adding a second argument to the upstart method, namespace equals firstNamespace.
If the namespace does not exist, it is created implicitly, I am running it.
Just like that, you can create more than one namespace.
Here, I am creating another namespace called secondNamespace and adding 2
random vectors to it.
I am fetching index statistics,
currently, there are 3 namespaces in the index, the default namespace empty string
contains 5 vectors, the firstNamespace contains 3 vectors and the
secondNamespace contains 2 vectors, there are a total of 10 vectors in the index.
All vector operations apply to a single namespace except describe index statistics.
I am fetching the vector with the ID x, index .h, IDs equals x.
If I run this code, it will return an empty vector because it queries the
default namespace and there is no vector with this ID.
The vector with the ID x is in the firstNamespace and I have to specify it explicitly.
I am adding namespace equals firstNamespace and I have got the vector,
that applies to any other operation, if you try to delete a vector you will have
to specify the namespace to which it belongs, index .delete of IDs equals x
and the namespace equals firstNamespace, I am running it, it was deleted so the
fetch operation returns an empty vector.
To delete all records from a namespace,
specify the deleteAll arguments to index .delete and provide a namespace argument,
index .delete of deleteAll equals true and the namespace equals firstNamespace,
note that deleting all records from a namespace also deletes the namespace
itself, I have deleted it, I am calling index .describeIndexStacks again, there
is no namespace called firstNamespace anymore, we have covered the concept of
namespaces, now let s take a break, in the upcoming section we ll consolidate
what we ve learned so far and dive into developing an app using LLMs, embeddings,
vectors and more, in the next video we ll explore splitting and embedding text
using Langchain, stay tuned!