avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2159

Abstract

B Atlas enables developers to leverage Atlas Vector Search as a Vector Store and also utilize MongoDB as a chat log history. Both LangChain and MongoDB share a focus on enhancing developer productivity.</p><p id="b808">To get started with MongoDB Atlas and LangChain, you can set up Vector Search, connect LangChain, and utilize pre-embedded data. Below is an example of how to load the sample data, define a vector index, and start finding neighbors using the approximate nearest neighbors algorithm.</p><div id="686c"><pre><span class="hljs-comment">// Connect to MongoDB Atlas</span> <span class="hljs-keyword">const</span> { <span class="hljs-title class_">MongoClient</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>);

<span class="hljs-keyword">const</span> uri = <span class="hljs-string">"your_mongodb_atlas_connection_string"</span>; <span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MongoClient</span>(uri);

<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">main</span>(<span class="hljs-params"></span>) { <span class="hljs-keyword">try</span> { <span class="hljs-keyword">await</span> client.<span class="hljs-title function_">connect</span>(); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"Connected to MongoDB Atlas"</span>);

<span class="hljs-comment">// Load sample data</span>
<span class="hljs-keyword">const</span> database = client.<span class="hljs-title function_">db</span>(<span class="hljs-string">"sample_mflix"</span>);
<span class="hljs-keyword">const</span> collection = database.<span class="hljs-title function_">collection</span>(<span class="hljs-string">"embedded_movies"</span>);
<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> collection.<span class="hljs-title function_">find</span>({}).<span class="hljs-title function_">toArray</span>();
<span class="hljs-variable language_">consol

Options

e</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"Sample data loaded:"</span>, data);

<span class="hljs-comment">// Define a vector index</span>
<span class="hljs-comment">// ...</span>

<span class="hljs-comment">// Find neighbors using the approximate nearest neighbors algorithm</span>
<span class="hljs-comment">// ...</span>

} <span class="hljs-keyword">finally</span> { <span class="hljs-keyword">await</span> client.<span class="hljs-title function_">close</span>(); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"Disconnected from MongoDB Atlas"</span>); } }

<span class="hljs-title function_">main</span>().<span class="hljs-title function_">catch</span>(<span class="hljs-variable language_">console</span>.<span class="hljs-property">error</span>);</pre></div><h2 id="a6f7">Conclusion</h2><p id="c626">The integration of LangChain with MongoDB Atlas provides developers with the capability to seamlessly incorporate vector search into their applications. As both platforms continue to evolve, there will be further enhancements and announcements in this space.</p><div id="da30" class="link-block"> <a href="https://readmedium.com/langchain-can-ai-companions-be-created-by-realchar-x-langsmith-320ce3d4666b"> <div> <div> <h2>LANGCHAIN — Can AI Companions Be Created by RealChar X LangSmith?</h2> <div><h3>The most profound technologies are those that disappear. They weave themselves into the fabric of everyday life until…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="d9e8">Stay tuned for more updates and new capabilities from the MongoDB team, and continue to engage with the community to ensure that the features provided meet the needs of developers.</p></article></body>

LANGCHAIN — What Is Langchain X MongoDB Atlas?

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. — Martin Fowler.

LangChain has recently integrated with MongoDB Atlas, a popular developer data platform. This integration aims to simplify the process of building AI-powered applications with semantic search capabilities using vector stores.

MongoDB Atlas — The Developer Data Platform

MongoDB Atlas is a fully managed database service offering that provides cloud-native support for various workloads, including transactional, search, analytical, and streaming. With the addition of Atlas Vector Search, MongoDB Atlas now supports storing vector embeddings alongside operational data and allows for dynamic updates using Atlas Triggers.

Introducing Atlas Vector Search

Atlas Vector Search eliminates the need to manage separate infrastructure for vector search by providing native support within MongoDB Atlas. This streamlines the process of adding vector search capabilities to applications and simplifies the query interface.

LangChain and MongoDB Atlas Integration

The integration of LangChain with MongoDB Atlas enables developers to leverage Atlas Vector Search as a Vector Store and also utilize MongoDB as a chat log history. Both LangChain and MongoDB share a focus on enhancing developer productivity.

To get started with MongoDB Atlas and LangChain, you can set up Vector Search, connect LangChain, and utilize pre-embedded data. Below is an example of how to load the sample data, define a vector index, and start finding neighbors using the approximate nearest neighbors algorithm.

// Connect to MongoDB Atlas
const { MongoClient } = require('mongodb');

const uri = "your_mongodb_atlas_connection_string";
const client = new MongoClient(uri);

async function main() {
  try {
    await client.connect();
    console.log("Connected to MongoDB Atlas");

    // Load sample data
    const database = client.db("sample_mflix");
    const collection = database.collection("embedded_movies");
    const data = await collection.find({}).toArray();
    console.log("Sample data loaded:", data);

    // Define a vector index
    // ...

    // Find neighbors using the approximate nearest neighbors algorithm
    // ...

  } finally {
    await client.close();
    console.log("Disconnected from MongoDB Atlas");
  }
}

main().catch(console.error);

Conclusion

The integration of LangChain with MongoDB Atlas provides developers with the capability to seamlessly incorporate vector search into their applications. As both platforms continue to evolve, there will be further enhancements and announcements in this space.

Stay tuned for more updates and new capabilities from the MongoDB team, and continue to engage with the community to ensure that the features provided meet the needs of developers.

Langchain
X
Mongodb
ChatGPT
Recommended from ReadMedium