Notebooks
M
MongoDB
Angle Embeddings Eval

Angle Embeddings Eval

agentsartificial-intelligencellmsmongodb-genai-showcaseevalsnotebooksgenerative-airag

Open In Colab

View Article

RAG Series Part 1: How to choose the right embedding model for your RAG application

This notebook evaluates the UAE-Large-V1 model.

Step 1: Install required libraries

  • datasets: Python library to get access to datasets available on Hugging Face Hub

- **sentence-transformers**: Framework for working with text and image embeddings

- **transformers**: Python library that provides APIs to interact with pre-trained models available on Hugging Face

- **numpy**: Python library that provides tools to perform mathematical operations on arrays

- **pandas**: Python library for data analysis, exploration and manipulation

- **tdqm**: Python module to show a progress meter for loops

[1]

Step 3: Download the evaluation dataset

We will use MongoDB's cosmopedia-wikihow-chunked dataset, which has chunked versions of WikiHow articles from the Cosmopedia dataset released by Hugging Face. The dataset is pretty large, so we will only grab the first 25k records for testing.

[2]

Step 4: Data analysis

Make sure the length of the dataset is what we expect (25k), preview the data, drop Nones etc.

[3]
25000
[4]
[5]
[6]
4335

Step 5: Creating embeddings

Define the embedding function, and run a quick test.

[7]
[8]
[9]
[10]
[11]
1024

Step 6: Evaluation

Measuring embedding latency

Create a local vector store (list) of embeddings for the entire dataset.

[12]
[13]
[14]
[15]
  0%|          | 0/196 [00:00<?, ?it/s]

Measuring retrieval quality

  • Create embedding for the user query

- Get the top 5 most similar documents from the local vector store using cosine similarity as the similarity metric

[16]
[17]
[18]
[19]
Query: Give me some tips to improve my mental health.
Score: 0.7515
Key Tips & Guidelines:

* Acknowledge that prioritizing mental health is not selfish but necessary for maintaining optimal functioning.
* Accept that everyone experiences ups and downs; seeking support when needed demonstrates strength rather than weakness.

Step 2: Practice Self-Awareness
Developing mindfulness skills allows individuals to become aware of their thoughts, feelings, and physical sensations without judgment. Being present in the moment fosters self-compassion, promotes relaxation, and enhances problem-solving abilities.

Key Tips & Guidelines:

* Set aside time each day for meditation or deep breathing exercises.
* Journal regularly to explore thoughts and emotions objectively.
* Engage in activities (e.g., yoga, tai chi) that encourage both physical movement and introspection.

Step 3: Establish Healthy Lifestyle Habits
Physical health significantly impacts mental well-being. Adopting healthy habits contributes to improved mood regulation, reduced anxiety symptoms, and enhanced cognitive function.

Key Tips & Guidelines:
--------
Score: 0.7452
Key Tips & Guidelines:

* Follow a balanced diet rich in fruits, vegetables, lean proteins, whole grains, and omega-3 fatty acids.
* Exercise consistently, aiming for at least 30 minutes per day most days of the week.
* Get sufficient sleep (7-9 hours nightly). Develop a bedtime routine and create a conducive sleeping environment.

Step 4: Cultivate Positive Relationships
Social connections play a vital role in promoting mental health. Building strong, supportive networks encourages open communication, empathy, and validation while combating loneliness and isolation.

Key Tips & Guidelines:

* Nurture existing friendships by scheduling regular meetups and engaging in shared interests.
* Seek out new social opportunities through clubs, classes, or volunteering.
* Learn to identify unhealthy relationship patterns and establish boundaries accordingly.

Step 5: Manage Stress Effectively
Chronic stress can wreak havoc on mental health. Implementing effective coping mechanisms enables individuals to navigate adversities constructively and minimize negative consequences.
--------
Score: 0.7256
Title: How to Care About Your Mental Health

Introduction:
Mental health is an essential aspect of overall well-being that often goes overlooked. Taking care of your mental health can help you lead a happier, more fulfilling life, increase productivity, strengthen relationships, and reduce stress levels. This comprehensive guide will provide you with actionable steps and valuable insights into caring about your mental health. By following these steps, you'll be better equipped to manage daily pressures, cope with setbacks, and maintain emotional balance.

Step 1: Recognize the Importance of Mental Health
Understanding why mental health matters is crucial before diving into strategies for improvement. Mental health affects every facet of our lives – from work performance to personal relationships. Prioritizing self-care and managing emotions contribute to increased resilience during challenging times. Additionally, taking charge of your mental health reduces the risk of developing severe psychological conditions such as depression or anxiety disorders.

Key Tips & Guidelines:
--------
[20]
Query: Give me some tips for writing good code.
Score: 0.7326
Step 6: Improve Code Quality
Strive for clean, readable, maintainable code. Adopt consistent naming conventions, indentation styles, and formatting rules. Utilize version control systems like Git to track changes and collaborate effectively. Leverage linters and static analyzers to enforce style guides automatically. Document your work using comments and dedicated documentation tools. High-quality code facilitates collaboration, promotes longevity, and simplifies troubleshooting.

Step 7: Embrace Best Practices
Follow established best practices relevant to your chosen language and domain. Examples include Object-Oriented Design Principles, SOLID principles, Test-Driven Development (TDD), Dependency Injection, Asynchronous Programming, etc. While seemingly overwhelming initially, integrating them gradually enhances design patterns, scalability, and extensibility. Consult authoritative blogs, books, and articles to stay updated on current trends and recommendations.
--------
Score: 0.6975
### Step 6: Read Books About Programming
Books offer comprehensive coverage, deep insights, best practices, historical context, and advanced topics unavailable in most online tutorials. Deliberately select texts targeting beginners yet providing progressive pathways towards proficiency. Popular recommendations include "Python Crash Course" by Eric Matthes, "Eloquent JavaScript" by Marijn Haverbeke, and "JavaScript & JQuery: Interactive Front-End Web Development" by Jon Duckett.

#### Key Tips & Guidelines
* Combine reading with active coding sessions to reinforce comprehension and application abilities.
* Take notes summarizing critical points, highlighting unfamiliar terminology, and jotting down potential areas for future study.
* Engage with author-recommended exercises, assignments, or challenges prompted throughout chapters.
--------
Score: 0.6656
Title: How to Become a Good Programmer

Introduction:
Programming is an essential skill in today's digital world. It opens up various opportunities in different industries such as software development, web development, data science, artificial intelligence, and many more. This comprehensive guide will provide you with actionable steps and valuable insights to become a good programmer. By following this tutorial, you'll learn programming fundamentals, best practices, and strategies for continuous improvement.

Step 1: Choose Your Programming Language
Choosing the right programming language is crucial when starting your coding journey. Key factors include your interests, career goals, and available resources. Some popular choices are Python (general-purpose), JavaScript (web development), Java (enterprise applications), or C# (game development). Research and select one that aligns with your objectives. For beginners, Python and JavaScript are great options due to their simplicity and versatility.
--------
[21]
Query: How do I create a basic webpage?
Score: 0.8068
Creating a webpage with basic HTML is an exciting endeavor that allows you to share information, showcase your creativity, or build the foundation for a more complex website. This comprehensive guide will walk you through each step required to create a simple yet effective static webpage using HTML (HyperText Markup Language), the standard language used to structure content on the World Wide Web.

**Step 1: Choose a Text Editor**

Before diving into coding, select a suitable text editor for writing your HTML code. Popular choices include Notepad++ (Windows), Visual Studio Code (cross-platform), Atom (cross-platform), and Sublime Text (cross-platform). These editors offer features such as syntax highlighting, auto-completion, and error detection, making them ideal for beginners and professionals alike.

Key tip: Avoid using word processors like Microsoft Word or Google Docs, as they may add unnecessary formatting codes that can interfere with your HTML.

**Step 2: Create an HTML Document**
--------
Score: 0.7550
Designing a personal web page can be an exciting and rewarding experience. It allows you to express yourself, showcase your skills or hobbies, and even build an online portfolio. This comprehensive guide will walk you through the process of creating your own personal webpage from scratch, with clear explanations, helpful tips, and best practices along the way.

### Part 1: Planning Your Personal Web Page

#### Step 1: Define Your Goals and Objectives

Before diving into design and development, take some time to reflect on what you want to accomplish with your personal web page. Here are some questions to consider:

* What is the primary purpose of your website? (e.g., resume, blog, portfolio)
* Who is your target audience? (e.g., potential employers, friends, like-minded enthusiasts)
* Which elements do you want to include on your site? (e.g., about me, contact form, photo gallery)
--------
Score: 0.7497
Step 4: Create Basic HTML Structure
Start building your codebit by adding basic HTML structure elements like `<!DOCTYPE html>`, `<html lang="en">`, `<head>`, and `<body>`. The DOCTYPE declaration sets the document type for modern web browsers; setting the language attribute within the `<html>` tag ensures proper rendering and screen reader support. Here is what the initial boilerplate code would look like:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document Title</title>
</head>
<body>
    <!-- Insert Content Here -->
</body>
</html>
```

Replace 'Document Title' with a suitable title for your page.

Key Tips & Guidelines:
--------
[22]
Query: What are some environment-friendly practices I can incorporate in everyday life?
Score: 0.7612
Step 15: Share Knowledge With Others
Educate friends, family, and colleagues about eco-friendly practices and benefits. Offer support during their transitions. Key tip: Lead by example without judgment. Guideline: Host workshops or discussion groups centered around sustainable living topics.

Conclusion:
By following these 15 steps, you'll become an earthy girl who embodies respect for our planet and its resources. Remember, every effort counts—big or small! Celebrate successes along the journey while striving for continuous improvement.
--------
Score: 0.7339
* **Carry Reusable Bags**: Keep cloth or other reusable shopping bags handy for grocery trips and errands. Store extra bags in your car, purse, or backpack for convenience.
* **Choose Sustainable Alternatives**: Opt for reusable water bottles, coffee cups, straws, and cutlery made from eco-friendly materials like stainless steel, glass, silicone, or bamboo.
* **Support Businesses that Minimize Packaging**: Patronize establishments that prioritize sustainable practices, such as using biodegradable packaging or offering package-free options.

Step 3: Conserve Energy and Water
Explanation: Efficient energy and water usage help decrease reliance on nonrenewable resources and lower greenhouse gas emissions.
--------
Score: 0.7062
* **Participate in Local Tree-Planting Initiatives**: Join citywide planting events organized by parks departments, schools, or environmental organizations. Volunteer at community gardens, nature preserves, or restoration projects.
* **Cultivate Native Flora**: Integrate regionally appropriate plants into home landscaping designs to support pollinators and provide ecosystem services. Remove invasive exotic species that outcompete natives and disrupt ecological balance.

Step 6: Adopt Eco-Friendly Transportation Methods
Explanation: Choosing alternative transportation modes decreases fossil fuel consumption and associated greenhouse gasses.
--------