Skip to content

Commit bec6007

Browse files
authored
Documentation for RAGStack TS (#372)
1 parent ae1c31d commit bec6007

File tree

4 files changed

+289
-1
lines changed

4 files changed

+289
-1
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
* xref:ROOT:packages.adoc[]
66
* xref:ROOT:migration.adoc[]
77
8+
UNCOMMENT WHEN READY TO PUBLISH
9+
.Get Started (TS/JS)
10+
* xref:ragstack-ts:quickstart.adoc[]
11+
* xref:ragstack-ts:migration.adoc[]
12+
813
.RAG Default architecture
914
* xref:default-architecture:index.adoc[]
1015
* xref:default-architecture:loading.adoc[]
@@ -51,4 +56,5 @@
5156
* xref:ROOT:tests.adoc[]
5257
5358
.Release notes
54-
* xref:ROOT:changelog.adoc[]
59+
* xref:ROOT:changelog.adoc[]
60+
* xref:ragstack-ts:changelog.adoc[]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
= Changelog (TS/JS)
2+
3+
The RAGStack changelog provides information about new features, bug fixes, dependency versions and breaking changes in each release.
4+
5+
For more, see:
6+
7+
* https://github.com/datastax/ragstack-ai-ts/releases[GitHub releases^]{external-link-icon}
8+
9+
* https://www.npmjs.com/package/@datastax/ragstack-ai[NPM^]{external-link-icon}
10+
11+
12+
== 1.0.0
13+
14+
[caption=]
15+
.Dependencies
16+
[%autowidth]
17+
[cols="2*",options="header"]
18+
|===
19+
| Package | Version
20+
21+
22+
| @datastax/astra-db-ts
23+
| 1.0.1
24+
25+
| @langchain/azure-openai
26+
| 0.0.2
27+
28+
| @langchain/community
29+
| 0.2.4
30+
31+
| @langchain/core
32+
| 0.2.2
33+
34+
| @langchain/google-vertexai
35+
| 0.0.17
36+
37+
| @langchain/openai
38+
| 0.0.34
39+
40+
| cassandra-driver
41+
| 4.7.2
42+
43+
| langchain
44+
| 0.2.3
45+
46+
| langsmith
47+
| 0.1.8
48+
49+
50+
|===
51+
52+
53+
== 0.1.1
54+
55+
[caption=]
56+
.Dependencies
57+
[%autowidth]
58+
[cols="2*",options="header"]
59+
|===
60+
| Package | Version
61+
62+
63+
| @datastax/astra-db-ts
64+
| 0.1.4
65+
66+
| @langchain/azure-openai
67+
| 0.0.2
68+
69+
| @langchain/community
70+
| 0.0.33
71+
72+
| @langchain/core
73+
| 0.1.36
74+
75+
| @langchain/openai
76+
| 0.0.26
77+
78+
| cassandra-driver
79+
| 4.7.2
80+
81+
| langchain
82+
| 0.1.23
83+
84+
| langsmith
85+
| 0.1.8
86+
87+
88+
|===
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
= Migrate to RAGStack
2+
3+
Migrating existing LangChain applications to RAGStack is very easy.
4+
RAGStack comes with a set of pinned, tested versions of the LangChain libraries and integrations.
5+
6+
The RAGStack CLI is the recommended way to manage your RAGStack projects.
7+
With the `install` command you can safely add or change the RAGStack version without worrying about transitive dependencies versions.
8+
This is especially important because RAGStack is a stack of multiple packages that are tested together for compatibility, performance, and security.
9+
10+
You don't need to install the CLI, using `npx` is the recommended way to run it.
11+
12+
Move your terminal to the project you want to install RAGStack in and run the following command:
13+
[source,bash]
14+
----
15+
npx @datastax/ragstack-ai-cli install
16+
----
17+
18+
This command will modify the `package.json`, install `@datastax/ragstack-ai` and refresh your local dependencies.
19+
The supported package managers are `npm` and `yarn` (both classic and berry).
20+
21+
The CLI automatically detects the package manager you are using and installs the correct version of RAGStack.
22+
However, if you never built the project before, it's recommended to force a specific package manager by setting the `--use-npm` or `--use-yarn` option.
23+
24+
25+
`@datastax/ragstack-ai` only includes a subset of the LangChain libraries, therefore you might want to keep some `@langchain/*` packages that are not included in RAGStack.
26+
To check what packages are included in RAGStack, you can run the following command:
27+
[source,bash]
28+
----
29+
npm show @datastax/ragstack-ai dependencies
30+
----
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
= Quickstart with RAGStack for TS
2+
3+
This quickstart demonstrates a basic RAG pattern using RAGStack TS and the vector-enabled {db-serverless} database to retrieve context and pass it to a language model for generation.
4+
5+
1. <<Construct information base>>
6+
2. <<Basic retrieval>>
7+
3. <<Generation with augmented context>>
8+
9+
== Setup
10+
11+
RAGStack TS includes all the standard libraries you need for the RAG pattern, including the vector database, embeddings pipeline, and retrieval.
12+
13+
. Create a new project using NPM or Yarn:
14+
+
15+
[tabs]
16+
======
17+
NPM::
18+
+
19+
[source,bash]
20+
----
21+
npm init
22+
----
23+
24+
Yarn::
25+
+
26+
[source,console]
27+
----
28+
yarn init
29+
----
30+
======
31+
32+
. Then add the RAGStack package via the CLI:
33+
+
34+
[tabs]
35+
======
36+
NPM::
37+
+
38+
[source,bash]
39+
----
40+
npx @datastax/ragstack-ai-ts install --use-npm
41+
----
42+
43+
Yarn::
44+
+
45+
[source,console]
46+
----
47+
npx @datastax/ragstack-ai-ts install --use-yarn
48+
----
49+
======
50+
+
51+
. Set the AstraDB vector credentials. If you don't have a vector database, create one at https://astra.datastax.com/.
52+
+
53+
[source,bash]
54+
----
55+
export ASTRA_DB_APPLICATION_TOKEN=AstraCS:xx
56+
export ASTRA_DB_API_ENDPOINT=https://xx.apps.astra.datastax.com
57+
----
58+
The {db-serverless} application token is associated automatically with the Database Administrator permission. An auth token example: `AstraCS:WSnyFUhRxsrg...`).
59+
+
60+
Both the endpoint and the token are available in the {astra-ui}.
61+
+
62+
. Create an OpenAI key at https://platform.openai.com/ and set it as an environment variable:
63+
+
64+
[source,bash]
65+
----
66+
export OPENAI_API_TOKEN=sk-xx
67+
----
68+
69+
== RAG workflow
70+
71+
With your environment set up, you're ready to create a RAG workflow in Javascript.
72+
Create a new file, `index.js`, and copy the following code:
73+
74+
[source,javascript]
75+
----
76+
const { OpenAIEmbeddings, ChatOpenAI } = require("@langchain/openai")
77+
const { AstraDBVectorStore } = require("@langchain/community/vectorstores/astradb")
78+
const { ChatPromptTemplate } = require("@langchain/core/prompts")
79+
const { RunnableSequence, RunnablePassthrough } = require("@langchain/core/runnables")
80+
const { StringOutputParser } = require("@langchain/core/output_parsers")
81+
82+
83+
async function main() {
84+
// create the embeddings object with the OpenAI API key
85+
const embeddings = new OpenAIEmbeddings()
86+
87+
// AstraDB connection parameters
88+
const astra = {
89+
token: process.env.ASTRA_DB_APPLICATION_TOKEN,
90+
endpoint: process.env.ASTRA_DB_API_ENDPOINT,
91+
collection: "demo",
92+
collectionOptions: {
93+
vector: {
94+
dimension: 1536, /** 1536 for OpenAI embeddings */
95+
metric: "cosine",
96+
},
97+
}
98+
}
99+
100+
/** Index some text into the Astra Vector Store */
101+
102+
const vectorStore = await AstraDBVectorStore.fromTexts(
103+
[
104+
"RAGStack is a framework for building RAG applications",
105+
"RAGStack has first-class support for AstraDB and Cassandra",
106+
],
107+
[{source: "documentation"}, {source: "documentation"}],
108+
embeddings,
109+
astra
110+
)
111+
/** Now prepare the retrieval */
112+
const prompt = ChatPromptTemplate.fromMessages([
113+
["system", "You're an helpful assistant. Help the user to understand what is RAGStack. Use only information provided in the CONTEXT.\nCONTEXT:\n{context}"],
114+
["human", "{question}"],
115+
])
116+
117+
const docParser = (docs) => {
118+
const formatted = docs.map((doc, i) => {
119+
return `<doc id='${i}'>${doc.pageContent}</doc>`
120+
}).join("\n")
121+
return formatted
122+
}
123+
124+
const chain = RunnableSequence.from([
125+
{
126+
context: vectorStore.asRetriever().pipe(docParser),
127+
question: new RunnablePassthrough(),
128+
},
129+
prompt,
130+
new ChatOpenAI({}),
131+
new StringOutputParser()
132+
]);
133+
/** Finally ask a question about RAGStack to the chatbot */
134+
const answer = await chain.invoke("What is RAGStack?")
135+
console.log("Answer:", answer)
136+
}
137+
main()
138+
----
139+
140+
After that, you can run the script with Node.js:
141+
[source,bash]
142+
----
143+
node index.js
144+
>Connected to Astra DB collection
145+
>Answer: RAGStack is a framework for building RAG applications. It also has first-class support for AstraDB and Cassandra.
146+
----
147+
148+
== Upgrade RAGStack version
149+
After you have installed the RAGStack package, you can upgrade it to the latest version using the re-running the cli command:
150+
[source,bash]
151+
----
152+
npx @datastax/ragstack-ai-ts install
153+
----
154+
or you can upgrade to a specific version:
155+
[source,bash]
156+
----
157+
npx @datastax/ragstack-ai-ts install x.y.z
158+
----
159+
160+
161+
== What's next?
162+
163+
* xref:what-is-rag.adoc[]: Learn more about the RAG pattern.
164+

0 commit comments

Comments
 (0)