forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add namespace support and improve examples
- Loading branch information
1 parent
9ba4547
commit 6c46990
Showing
8 changed files
with
98 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
AstraDBVectorStore, | ||
Document, | ||
storageContextFromDefaults, | ||
VectorStoreIndex, | ||
} from "llamaindex"; | ||
|
||
const collectionName = "test_collection"; | ||
|
||
async function main() { | ||
try { | ||
const docs = [ | ||
new Document({ | ||
text: "AstraDB is built on Apache Cassandra", | ||
metadata: { | ||
id: 123, | ||
}, | ||
}), | ||
new Document({ | ||
text: "AstraDB is a NoSQL DB", | ||
metadata: { | ||
id: 456, | ||
}, | ||
}), | ||
new Document({ | ||
text: "AstraDB supports vector search", | ||
metadata: { | ||
id: 789, | ||
}, | ||
}), | ||
]; | ||
|
||
const astraVS = new AstraDBVectorStore(); | ||
await astraVS.create(collectionName, { | ||
vector: { dimension: 1536, metric: "cosine" }, | ||
}); | ||
await astraVS.connect(collectionName); | ||
|
||
const ctx = await storageContextFromDefaults({ vectorStore: astraVS }); | ||
const index = await VectorStoreIndex.fromDocuments(docs, { | ||
storageContext: ctx, | ||
}); | ||
|
||
const queryEngine = index.asQueryEngine(); | ||
const response = await queryEngine.query({ | ||
query: "Describe AstraDB.", | ||
}); | ||
|
||
console.log(response.toString()); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
main(); |
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
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
Oops, something went wrong.