8/26/2024

Exploring Embedding Capabilities with Ollama

In the world of AI, Embeddings are like the secret sauce that helps transform complex textual data into understandable numerical formats that machines can recognize. As we dive into the latest and greatest in this realm, let's take a closer look at what Ollama offers in terms of embedding capabilities.

What are Embedding Models?

Embedding models are specialized tools designed to generate vector embeddings, which are essentially LONG ARRAYS of numbers. These numbers are crucial as they represent the SEMANTIC meaning of given sequences of text. You might wonder, what do these embeddings actually do? By storing these vector embeddings in databases, systems can easily compare and search for data that shares similar meanings. This capability is vital for building advanced applications like Retrieval-Augmented Generation (RAG) apps, which combine text prompts with existing documents and data to generate insightful responses.

Ollama's Embedding Models

Ollama has jumped into the embedding game with support for several standout models:
  • mxbai-embed-large: With 334 million parameters, this model is KNOWN for its versatility and ability to handle large datasets in various domains. It's like the Swiss Army knife of embedding models! You can view it here.
  • nomic-embed-text: This model has 137 million parameters and is noted for outperforming many existing embedding solutions, especially in long-context tasks. If you’re looking for reliability, this one’s a great option. Check it out here.
  • all-minilm: A compact option with just 23 million parameters, all-minilm excels in generating efficient sentence-level embeddings and is particularly effective for granular tasks like clustering and semantic searches. You can find more about it here.

Getting Started with Ollama

To unleash the power of Ollama's embedding capabilities, the first step is to PULL the desired model using the command line. Here's how you can do it:
1 ollama pull mxbai-embed-large
This command updates your local setup with the selected model, ready to dive into embedding magic!

Endpoints for Embeddings Generation

Once you've applied your commands, you can start generating embeddings using either the REST API or supported libraries like Python and JavaScript. Here are some examples:
REST API:
1 curl http://localhost:11434/api/embeddings -d '{ "model": "mxbai-embed-large", "prompt": "Llamas members camelid family" }'
Python Library:
1 2 python ollama.embeddings(model='mxbai-embed-large', prompt='Llamas members camelid family')
JavaScript Library:
1 2 javascript ollama.embeddings({ model: 'mxbai-embed-large', prompt: 'Llamas members camelid family' })

Embedding Application Example: Building a RAG Application

Let’s walk through a simple example to build a RAG application using Ollama’s embedding models:

Step 1: Generate Embeddings

First, install the necessary libraries:
1 2 bash pip install ollama chromadb
Then create a Python file named
1 example.py
with the following content: ```python import ollama import chromadb
documents = [ "Llamas members camelid family meaning they're closely related to vicuñas and camels", "Llamas were first domesticated and used as pack animals 4,000 to 5,000 years ago in the Peruvian highlands", "Llamas can grow up to 6 feet tall, with the average being between 5 feet 6 inches and 5 feet 9 inches tall", "They weigh between 280 to 450 pounds and can carry 25 to 30 percent of their body weight", "Llamas are vegetarians with efficient digestive systems", "They can live anywhere from 15 to 30 years old" ]
client = chromadb.Client() collection = client.create_collection(name="docs")
for i, d in enumerate(documents): response = ollama.embeddings(model="mxbai-embed-large", prompt=d) embedding = response["embedding"] collection.add(ids=[str(i)], embeddings=[embedding], documents=[d]) ```

Step 2: Retrieve Relevant Documents

Next, add code to retrieve relevant documents based on a prompt:
1 2 3 4 5 python prompt = "What animals are llamas related to?" response = ollama.embeddings(prompt=prompt, model="mxbai-embed-large") results = collection.query(query_embeddings=[response["embedding"]], n_results=1) data = results['documents'][0][0]

Step 3: Generate Answers

Finally, use the retrieved data to create a response:
1 2 3 python output = ollama.generate(model="llama2", prompt=f"Using data: {data}. Respond to the prompt: {prompt}") print(output['response'])
When you run this code, the model will intelligently respond using the data retrieved from your documents, showcasing just how powerful these embeddings can be.

Advantages of Using Ollama for Embedding Tasks

By choosing Ollama, you’re not just grabbing an embedding model. You’re gaining access to:
  • Convenience: A no-fuss, user-friendly interface lets you focus on the fun stuff—your application!
  • Customization: Tailor the experience to align with your brand and operational needs seamlessly.
  • Integration: With LangChain and LlamaIndex, you can effortlessly embed these models into broader workflows, enhancing their capabilities.

What’s Next for Ollama?

The Ollama team has exciting features coming soon, including:
  • Batch Embeddings: Send multiple input prompts simultaneously to streamline the process.
  • OpenAI API Compatibility: Expect an easier transition for existing models and tools.
  • More Embedding Model Architectures: Expanding the support to include other advanced architectures like ColBERT and RoBERTa.

Broaden Your Audience with Arsturn

Among the many ways to utilize the power of conversational AI is through Arsturn. At Arsturn, you can instantly create custom ChatGPT chatbots that help boost engagement & conversions on your website. This platform allows you to leverage AI technology to engage audiences effectively, serving as the perfect complement to your embedding capabilities. Arsturn empowers you to connect meaningfully with your audience, offering insights and instant responses through your chatbot.

Transform Your Engagement Today!

  • Effortless No-Code AI Chatbot Builder: Ideal for influencers and businesses alike.
  • Adaptable Data: Feed it any necessary information, supporting formats like PDFs and CSVs.
  • Insightful Analytics: Learn about your audience's preferences and behaviors.
Join thousands who are already using Arsturn to build powerful AI chatbots without technical hurdles!

Conclusion

Exploring the embedding capabilities with Ollama opens up a world of opportunities to enhance AI applications across various sectors. Whether you're building RAG applications or creating dynamic chatbots through platforms like Arsturn, the future of AI communication is BRIGHT.
Ready to dive deeper into the world of embeddings? Take advantage of Ollama’s diverse models and Arsturn's powerful chatbot solutions today!


Arsturn.com/
Claim your chatbot

Copyright © Arsturn 2024