## JaguarDB Vector Database

> \[JaguarDB Vector Database\]([http://www.jaguardb.com/windex.html](http://www.jaguardb.com/windex.html)
> 
> 1.  It is a distributed vector database
> 2.  The “ZeroMove” feature of JaguarDB enables instant horizontal scalability
> 3.  Multimodal: embeddings, text, images, videos, PDFs, audio, time series, and geospatial
> 4.  All-masters: allows both parallel reads and writes
> 5.  Anomaly detection capabilities
> 6.  RAG support: combines LLM with proprietary and real-time data
> 7.  Shared metadata: sharing of metadata across multiple vector indexes
> 8.  Distance metrics: Euclidean, Cosine, InnerProduct, Manhatten, Chebyshev, Hamming, Jeccard, Minkowski

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

There are two requirements for running the examples in this file. 1. You must install and set up the JaguarDB server and its HTTP gateway server. Please refer to the instructions in: [www.jaguardb.com](http://www.jaguardb.com/)

1.  You must install the http client package for JaguarDB:
    
    ```
        pip install -U jaguardb-http-client
    ```
    

## RAG With Langchain[​](#rag-with-langchain "Direct link to RAG With Langchain")

This section demonstrates chatting with LLM together with Jaguar in the langchain software stack.

```
from langchain_community.document_loaders import TextLoaderfrom langchain_community.vectorstores.jaguar import Jaguarfrom langchain_openai import OpenAIEmbeddingsfrom langchain_text_splitters import CharacterTextSplitter""" Load a text file into a set of documents """loader = TextLoader("../../modules/state_of_the_union.txt")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=300)docs = text_splitter.split_documents(documents)"""Instantiate a Jaguar vector store"""### Jaguar HTTP endpointurl = "http://192.168.5.88:8080/fwww/"### Use OpenAI embedding modelembeddings = OpenAIEmbeddings()### Pod is a database for vectorspod = "vdb"### Vector store namestore = "langchain_rag_store"### Vector index namevector_index = "v"### Type of the vector index# cosine: distance metric# fraction: embedding vectors are decimal numbers# float: values stored with floating-point numbersvector_type = "cosine_fraction_float"### Dimension of each embedding vectorvector_dimension = 1536### Instantiate a Jaguar store objectvectorstore = Jaguar(    pod, store, vector_index, vector_type, vector_dimension, url, embeddings)"""Login must be performed to authorize the client.The environment variable JAGUAR_API_KEY or file $HOME/.jagrcshould contain the API key for accessing JaguarDB servers."""vectorstore.login()"""Create vector store on the JaguarDB database server.This should be done only once."""# Extra metadata fields for the vector storemetadata = "category char(16)"# Number of characters for the text field of the storetext_size = 4096#  Create a vector store on the servervectorstore.create(metadata, text_size)"""Add the texts from the text splitter to our vectorstore"""vectorstore.add_documents(docs)""" Get the retriever object """retriever = vectorstore.as_retriever()# retriever = vectorstore.as_retriever(search_kwargs={"where": "m1='123' and m2='abc'"})""" The retriever object can be used with LangChain and LLM """
```

## Interaction With Jaguar Vector Store[​](#interaction-with-jaguar-vector-store "Direct link to Interaction With Jaguar Vector Store")

Users can interact directly with the Jaguar vector store for similarity search and anomaly detection.

```
from langchain_community.vectorstores.jaguar import Jaguarfrom langchain_openai import OpenAIEmbeddings# Instantiate a Jaguar vector store objecturl = "http://192.168.3.88:8080/fwww/"pod = "vdb"store = "langchain_test_store"vector_index = "v"vector_type = "cosine_fraction_float"vector_dimension = 10embeddings = OpenAIEmbeddings()vectorstore = Jaguar(    pod, store, vector_index, vector_type, vector_dimension, url, embeddings)# Login for authorizationvectorstore.login()# Create the vector store with two metadata fields# This needs to be run only once.metadata_str = "author char(32), category char(16)"vectorstore.create(metadata_str, 1024)# Add a list of textstexts = ["foo", "bar", "baz"]metadatas = [    {"author": "Adam", "category": "Music"},    {"author": "Eve", "category": "Music"},    {"author": "John", "category": "History"},]ids = vectorstore.add_texts(texts=texts, metadatas=metadatas)#  Search similar textoutput = vectorstore.similarity_search(    query="foo",    k=1,    metadatas=["author", "category"],)assert output[0].page_content == "foo"assert output[0].metadata["author"] == "Adam"assert output[0].metadata["category"] == "Music"assert len(output) == 1# Search with filtering (where)where = "author='Eve'"output = vectorstore.similarity_search(    query="foo",    k=3,    fetch_k=9,    where=where,    metadatas=["author", "category"],)assert output[0].page_content == "bar"assert output[0].metadata["author"] == "Eve"assert output[0].metadata["category"] == "Music"assert len(output) == 1# Anomaly detectionresult = vectorstore.is_anomalous(    query="dogs can jump high",)assert result is False# Remove all data in the storevectorstore.clear()assert vectorstore.count() == 0# Remove the store completelyvectorstore.drop()# Logoutvectorstore.logout()
```