-
Notifications
You must be signed in to change notification settings - Fork 0
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
DOC-3881: Revert to Highlight.js, fix admonition issues #112
Merged
Conversation
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
colegoldsmith
approved these changes
Feb 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I tested locally and saw different languages highlighting properly. Colors seem good in light and dark modes
Stress-tested things with the following syntax, and things look good! = {astra_db} FAQs
:slug: datastax-astra-faq
Frequently asked questions about {company} {astra_db}.
[IMPORTANT]
======
Data is not directly protected by TDE when you access the data using the following utilities.
[cols="1,3"]
|===
| Utility | Reason utility is not encrypted
| nodetool
| Uses only JMX, so data is not accessed.
| sstableloader
| Operates directly on the SSTables.
| sstablescrub
| Operates directly on the SSTables.
| sstableutil
| Operates directly on the SSTables.
| sstableverify
| Operates directly on the SSTables.
|===
[NOTE]
====
A note.
====
======
[NOTE]
======
A note.
[NOTE]
====
Another admonition.
====
======
[NOTE]
======
A note.
[IMPORTANT]
====
Another admonition.
====
======
[NOTE]
======
A note.
[TIP]
====
Another admonition.
====
======
[NOTE]
======
A note.
[WARNING]
====
Another admonition.
====
======
[NOTE]
======
A note.
[CAUTION]
====
Another admonition.
====
======
[tabs]
======
Python::
+
.quickstart.py
[source,python]
----
# tag::init[]
import os
from astrapy.db import AstraDB
# Initialize the client
db = AstraDB(
token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
api_endpoint=os.environ["ASTRA_DB_API_ENDPOINT"],
)
# end::init[]
# tag::collection[]
# Create a collection
collection = db.create_collection("vector_test", dimension=5, metric="cosine")
# end::collection[]
# tag::data[]
# Insert documents into the collection
documents = [
{
"_id": "1",
"text": "ChatGPT integrated sneakers that talk to you",
"$vector": [0.1, 0.15, 0.3, 0.12, 0.05],
},
{
"_id": "2",
"text": "An AI quilt to help you sleep forever",
"$vector": [0.45, 0.09, 0.01, 0.2, 0.11],
},
{
"_id": "3",
"text": "A deep learning display that controls your mood",
"$vector": [0.1, 0.05, 0.08, 0.3, 0.6],
},
]
res = collection.insert_many(documents)
# end::data[]
# tag::search[]
# Perform a similarity search
query = [0.15, 0.1, 0.1, 0.35, 0.55]
results = collection.vector_find(query, limit=2, fields={"text", "$vector"})
for document in results:
print(document)
# end::search[]
# tag::delete[]
# Delete the collection
db.delete_collection(collection_name="vector_test")
# end::delete[]
----
+
[NOTE]
====
Don't name the file `astrapy.py` to avoid a namespace collision.
====
TypeScript::
+
.quickstart.ts
[source,typescript]
----
// tag::init[]
import { AstraDB } from "@datastax/astra-db-ts";
async function main() {
const { ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT } = process.env;
// Initialize the client
const db = new AstraDB(ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT);
// end::init[]
// tag::collection[]
// Create a collection
await db.createCollection(
"vector_test",
{
"vector": {
"dimension": 5,
"metric": "cosine"
}
}
);
const collection = await db.collection("vector_test");
// end::collection[]
// tag::data[]
// Insert documents into the collection
const documents = [
{
"_id": "1",
"text": "ChatGPT integrated sneakers that talk to you",
"$vector": [0.1, 0.15, 0.3, 0.12, 0.05],
},
{
"_id": "2",
"text": "An AI quilt to help you sleep forever",
"$vector": [0.45, 0.09, 0.01, 0.2, 0.11],
},
{
"_id": "3",
"text": "A deep learning display that controls your mood",
"$vector": [0.1, 0.05, 0.08, 0.3, 0.6],
}
];
const results = await collection.insertMany(documents);
// end::data[]
// tag::search[]
// Define the search options
const options = {
sort: {
"$vector": [0.15, 0.1, 0.1, 0.35, 0.55],
},
limit: 5
};
// Perform a similarity search
collection.find({}, options).toArray().then(docs => {
docs.forEach(doc => console.log(doc));
});
// end::search[]
// tag::delete[]
// Delete the collection
db.dropCollection("vector_test").then(response => {
console.log(response);
});
// end::delete[]
// tag::end[]
}
main().catch(console.error);
// end::end[]
----
Java::
+
.src/main/java/com/example/Quickstart.java
[source,java]
----
// tag::init[]
package com.example;
import com.dtsx.astra.sdk.AstraDB;
import com.dtsx.astra.sdk.AstraDBCollection;
import io.stargate.sdk.data.domain.JsonDocument;
import io.stargate.sdk.data.domain.JsonDocumentResult;
import io.stargate.sdk.data.domain.SimilarityMetric;
import io.stargate.sdk.data.domain.CollectionDefinition;
import java.util.List;
import java.util.stream.Stream;
public class Quickstart {
public static void main(String[] args) {
// Loading Arguments
String astraToken = System.getenv("ASTRA_DB_APPLICATION_TOKEN");
String astraApiEndpoint = System.getenv("ASTRA_DB_API_ENDPOINT");
// Initialize the client
AstraDB db = new AstraDB(astraToken, astraApiEndpoint);
System.out.println("Connected to AstraDB");
// end::init[]
// tag::collection[]
// Create a collection
CollectionDefinition colDefinition = CollectionDefinition.builder()
.name("vector_test")
.vector(5, SimilarityMetric.cosine)
.build();
db.createCollection(colDefinition);
AstraDBCollection collection = db.collection("vector_test");
// end::collection[]
// tag::data[]
// Insert documents into the collection
collection.insertMany(List.of(
new JsonDocument()
.id("1")
.put("text", "ChatGPT integrated sneakers that talk to you")
.vector(new float[]{0.1f, 0.15f, 0.3f, 0.12f, 0.05f}),
new JsonDocument()
.id("2")
.put("text", "An AI quilt to help you sleep forever")
.vector(new float[]{0.45f, 0.09f, 0.01f, 0.2f, 0.11f}),
new JsonDocument()
.id("3")
.put("text", "A deep learning display that controls your mood")
.vector(new float[]{0.1f, 0.05f, 0.08f, 0.3f, 0.6f})
));
// end::data[]
// tag::search[]
// Perform a similarity search
Stream<JsonDocumentResult> resultsSet = collection.findVector(
new float[]{0.15f, 0.1f, 0.1f, 0.35f, 0.55f},
10
);
resultsSet.forEach(System.out::println);
// end::search[]
// tag::delete[]
// Delete the collection
db.deleteCollection("vector_test");
// end::delete[]
// tag::end[]
}
}
// end::end[]
----
====== Ignore the streaking green coming off the NOTE (artifact of screenshot app). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To test highlight.js, check for code callout rendering:
To test admonitions: