-
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.
community[patch]: Upstash Vector Store Namespace Feature (#5557)
* feat: Upstash Vector Namespace feature * add: Upstash Vector Namespace Tests * docs: Upstash Vector namespace * fmt
- Loading branch information
1 parent
079931f
commit ff47bd2
Showing
7 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
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
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
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,50 @@ | ||
import { Index } from "@upstash/vector"; | ||
import { OpenAIEmbeddings } from "@langchain/openai"; | ||
import { Document } from "@langchain/core/documents"; | ||
import { UpstashVectorStore } from "@langchain/community/vectorstores/upstash"; | ||
|
||
const index = new Index({ | ||
url: process.env.UPSTASH_VECTOR_REST_URL as string, | ||
token: process.env.UPSTASH_VECTOR_REST_TOKEN as string, | ||
}); | ||
|
||
const embeddings = new OpenAIEmbeddings({}); | ||
|
||
const UpstashVector = new UpstashVectorStore(embeddings, { | ||
index, | ||
namespace: "test-namespace", | ||
}); | ||
|
||
// Creating the docs to be indexed. | ||
const id = new Date().getTime(); | ||
const documents = [ | ||
new Document({ | ||
metadata: { name: id }, | ||
pageContent: "Vector databases are great!", | ||
}), | ||
]; | ||
|
||
// Creating embeddings from the provided documents, and adding them to target namespace in Upstash Vector database. | ||
await UpstashVector.addDocuments(documents); | ||
|
||
// Waiting vectors to be indexed in the vector store. | ||
// eslint-disable-next-line no-promise-executor-return | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
const queryResult = await UpstashVector.similaritySearchWithScore( | ||
"Vector database", | ||
1 | ||
); | ||
|
||
console.log(queryResult); | ||
/** | ||
[ | ||
[ | ||
Document { | ||
pageContent: 'Vector databases are great!', | ||
metadata: [Object] | ||
}, | ||
0.9016147 | ||
], | ||
] | ||
*/ |
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
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
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
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