Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding azion edgesql integration to langchain-community #7344

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/core_docs/docs/integrations/retrievers/azion-edgesql.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Azion Edge SQL Retriever

The `AzionRetriever` is used to perform advanced search operations, including hybrid and similarity searches directly on Azion's Edge Plataform using Edge SQL. Make sure to install the `@langchain/community` package to use this retriever. Besides that, you will need an Azion account and a Token to use the Azion API, configuring it as environment variable `AZION_TOKEN`.

```typescript
import { AzionRetriever } from "@langchain/community/retrievers/azion";
import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";

// Initialize the retriever
const embeddingModel = new OpenAIEmbeddings({ model: "text-embedding-3-small" });
// Initialize the entity extractor model to extract the entities to perform Full Text Search operations
const entityExtractor = new ChatOpenAI({ model: "gpt-4o-mini" });

// Initialize the retriever
const retriever = new AzionRetriever(embeddingModel, entityExtractor, {
dbName: "mydb",
similarityK: 2,
ftsK: 2,
searchType: "hybrid",
// Filter documents by language = "en" AND topic IN ("nature", "biology")
filters: [
// Only return English language documents
{ column: "language", operator: "=", value: "en" },
// Only return documents with topics of nature or biology
{ column: "topic", operator: "IN", value: "'nature', 'biology'" }
],
// Return only the topic and language metadata
metadataItems: ["topic", "language"]
});

// Perform a search
const documents = await retriever._getRelevantDocuments("Australia");
console.log(documents);
```

Using AzionRetriever as a tool in an agent requires the `createRetrieverTool` function to wrap the retriever:

```typescript
import {createRetrieverTool} from "@langchain/core/tools";
import {AzionRetriever} from "./src/function/AzionRetriever";

const retriever = new AzionRetriever(embeddingModel, entityExtractor, {
dbName: "mydb",
similarityK: 2,
ftsK: 2,
});

const retrieverTool = createRetrieverTool(retriever, {
name: "AzionRetriever",
description: "A tool that retrieves documents from a vector database"
});

```
39 changes: 39 additions & 0 deletions docs/core_docs/docs/integrations/vectorstores/azion-edgesql.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
### Azion Edge SQL Vector Store
The `AzionVectorStore` is used to manage and search through a collection of documents using vector embeddings, directly on Azion's Edge Plataform using Edge SQL. Make sure to install the `@langchain/community` package to use this vector store. Besides that, you will need an Azion account and a Token to use the Azion API, configuring it as environment variable `AZION_TOKEN`.

```typescript
import { AzionVectorStore } from "@langchain/community/vectorstores/azionedgesql";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";

// Initialize the vector store
const embeddingModel = new OpenAIEmbeddings({ model: "text-embedding-3-small" });
const vectorStore = new AzionVectorStore(embeddingModel, { dbName: "mydb", tableName: "documents" });

// Setup database with hybrid search and metadata columns
await vectorStore.setupDatabase({
columns: ["topic", "language"],
mode: "hybrid"
});

//OR you can setup the database with the static method createDatabase
//const vectorStore = await AzionVectorStore.createDatabase(embeddingModel,{dbName:"mydb", tableName:"documents"}, {columns: ["topic", "language"], mode: "hybrid"});

// Add documents to the vector store
await vectorStore.addDocuments([
new Document({ pageContent: "Australia is known for its unique wildlife", metadata: { topic: "nature", language: "en" } }),
// Add more documents as needed
]);

// Perform a similarity search
const results = await vectorStore.AzionSimilaritySearch("Australia", { kvector: 1, metadataItems: ["topic"] });

// OR
// Perform a full text search
const results = await vectorStore.AzionFullTextSearch("Australia", { kfts: 1, metadataItems: ["topic"] });

// OR
// Perform a hybrid search
const results = await vectorStore.AzionHybridSearch("Australia", { kfts: 1, kvector: 1, metadataItems: ["topic"] });
console.log(results);
```
4 changes: 4 additions & 0 deletions libs/langchain-community/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const config = {
// vectorstores
"vectorstores/analyticdb": "vectorstores/analyticdb",
"vectorstores/astradb": "vectorstores/astradb",
"vectorstores/azion_edgesql": "vectorstores/azion_edgesql",
"vectorstores/azure_aisearch": "vectorstores/azure_aisearch",
"vectorstores/azure_cosmosdb": "vectorstores/azure_cosmosdb",
"vectorstores/cassandra": "vectorstores/cassandra",
Expand Down Expand Up @@ -196,6 +197,7 @@ export const config = {
// retrievers
"retrievers/amazon_kendra": "retrievers/amazon_kendra",
"retrievers/amazon_knowledge_base": "retrievers/amazon_knowledge_base",
"retrievers/azion_edgesql": "retrievers/azion_edgesql",
"retrievers/bm25": "retrievers/bm25",
"retrievers/chaindesk": "retrievers/chaindesk",
"retrievers/databerry": "retrievers/databerry",
Expand Down Expand Up @@ -377,6 +379,7 @@ export const config = {
"llms/layerup_security",
"vectorstores/analyticdb",
"vectorstores/astradb",
"vectorstores/azion_edgesql",
"vectorstores/azure_aisearch",
"vectorstores/azure_cosmosdb",
"vectorstores/cassandra",
Expand Down Expand Up @@ -434,6 +437,7 @@ export const config = {
"chat_models/zhipuai",
"retrievers/amazon_kendra",
"retrievers/amazon_knowledge_base",
"retrievers/azion_edgesql",
"retrievers/dria",
"retrievers/metal",
"retrievers/supabase",
Expand Down
Loading