-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding azion edgesql integration to langchain-community
- Loading branch information
1 parent
1b7e34e
commit 69400bc
Showing
6 changed files
with
1,692 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
docs/core_docs/docs/integrations/retrievers/azion-edgesql.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
```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
39
docs/core_docs/docs/integrations/vectorstores/azion-edgesql.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
```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); | ||
``` |
Oops, something went wrong.