ApertureDB is a database that stores, indexes, and manages multi-modal data like text, images, videos, bounding boxes, and embeddings, together with their associated metadata.This notebook explains how to use the embeddings functionality of ApertureDB.
To continue, you should have an ApertureDB instance up and running and configure your environment to use it.
There are various ways to do that, for example:
Copy
Ask AI
docker run --publish 55555:55555 aperturedata/aperturedb-standaloneadb config create local --active --no-interactive
We want to use OllamaEmbeddings so we have to import the necessary modules.Ollama can be set up as a docker container as described in the documentation, for example:
Copy
Ask AI
# Run serverdocker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama# Tell server to load a specific modeldocker exec ollama ollama run llama2
Copy
Ask AI
from langchain_community.embeddings import OllamaEmbeddingsembeddings = OllamaEmbeddings()
This code creates a vectorstore in the ApertureDB instance.
Within the instance, this vectorstore is represented as a “descriptor set”.
By default, the descriptor set is named langchain. The following code will generate embeddings for each document and store them in ApertureDB as descriptors. This will take a few seconds as the embeddings are bring generated.
Copy
Ask AI
from langchain_community.vectorstores import ApertureDBvector_db = ApertureDB.from_documents(documents, embeddings)
Now we have all the components we need to create a RAG (Retrieval-Augmented Generation) chain. This chain does the following:
Generate embedding descriptor for user query
Find text segments that are similar to the user query using the vector store
Pass user query and context documents to the LLM using a prompt template
Return the LLM’s answer
Copy
Ask AI
# Create promptfrom langchain_core.prompts import ChatPromptTemplateprompt = ChatPromptTemplate.from_template("""Answer the following question based only on the provided context:<context>{context}</context>Question: {input}""")# Create a chain that passes documents to an LLMfrom langchain.chains.combine_documents import create_stuff_documents_chaindocument_chain = create_stuff_documents_chain(llm, prompt)# Treat the vectorstore as a document retrieverretriever = vector_db.as_retriever()# Create a RAG chain that connects the retriever to the LLMfrom langchain.chains import create_retrieval_chainretrieval_chain = create_retrieval_chain(retriever, document_chain)
Copy
Ask AI
Based on the provided context, ApertureDB can store images. In fact, it is specifically designed to manage multimodal data such as images, videos, documents, embeddings, and associated metadata including annotations. So, ApertureDB has the capability to store and manage images.
Finally we pass a question to the chain and get our answer. This will take a few seconds to run as the LLM generates an answer from the query and context documents.
Copy
Ask AI
user_query = "How can ApertureDB store images?"response = retrieval_chain.invoke({"input": user_query})print(response["answer"])
Copy
Ask AI
Based on the provided context, ApertureDB can store images in several ways:1. Multimodal data management: ApertureDB offers a unified interface to manage multimodal data such as images, videos, documents, embeddings, and associated metadata including annotations. This means that images can be stored along with other types of data in a single database instance.2. Image storage: ApertureDB provides image storage capabilities through its integration with the public cloud providers or on-premise installations. This allows customers to host their own ApertureDB instances and store images on their preferred cloud provider or on-premise infrastructure.3. Vector database: ApertureDB also offers a vector database that enables efficient similarity search and classification of images based on their semantic meaning. This can be useful for applications where image search and classification are important, such as in computer vision or machine learning workflows.Overall, ApertureDB provides flexible and scalable storage options for images, allowing customers to choose the deployment model that best suits their needs.
Assistant
Responses are generated using AI and may contain mistakes.