docs: add deprecation warnings for addNoun and addVerb methods

- Add @deprecated JSDoc tags to TypeScript definitions
- Update all documentation examples to use modern add() and relate() API
- Preserve batch operations (addNouns, addVerbs) as they remain current
- Mark deprecated methods in both source and compiled definitions

Migration guide:
- addNoun(data, type, metadata) → add(data, { nounType: type, ...metadata })
- addVerb(source, target, type, metadata) → relate(source, target, type, metadata)
This commit is contained in:
David Snelling 2025-09-17 10:48:41 -07:00
parent 20a54fbb7e
commit 2128ef5607
21 changed files with 343 additions and 331 deletions

View file

@ -404,7 +404,7 @@ const brain = new BrainyData()
await brain.init()
// You're now running the same tech as Fortune 500 companies
await brain.addNoun("Your data is enterprise-grade", {
await brain.add("Your data is enterprise-grade", {
secure: true,
durable: true,
scalable: true,

View file

@ -56,7 +56,7 @@ await brain.init()
```typescript
// Add entities (nouns) with automatic embedding generation
const id = await brain.addNoun("The quick brown fox jumps over the lazy dog", {
const id = await brain.add("The quick brown fox jumps over the lazy dog", {
category: "demo",
timestamp: Date.now()
})
@ -64,9 +64,9 @@ const id = await brain.addNoun("The quick brown fox jumps over the lazy dog", {
console.log(`Added noun with ID: ${id}`)
// Add relationships (verbs) between entities
const sourceId = await brain.addNoun("John Smith", 'person')
const targetId = await brain.addNoun("TechCorp", 'organization')
await brain.addVerb(sourceId, targetId, "works_at", {
const sourceId = await brain.add("John Smith", { nounType: 'person' })
const targetId = await brain.add("TechCorp", { nounType: 'organization' })
await brain.relate(sourceId, targetId, "works_at", {
position: "Engineer",
since: "2024"
})
@ -118,7 +118,7 @@ const documents = [
]
for (const doc of documents) {
await brain.addNoun(doc.content, {
await brain.add(doc.content, {
title: doc.title,
type: "document"
})
@ -132,7 +132,7 @@ const results = await brain.search("how do neural networks work")
```typescript
// Add user interactions as nouns
const interactionId = await brain.addNoun("user viewed product", {
const interactionId = await brain.add("user viewed product", {
userId: "user123",
productId: "product456",
action: "view",
@ -140,9 +140,9 @@ const interactionId = await brain.addNoun("user viewed product", {
})
// Create relationships between users and products
const userId = await brain.addNoun("user123", 'user')
const productId = await brain.addNoun("product456", 'product')
await brain.addVerb(userId, productId, "viewed", {
const userId = await brain.add("user123", { nounType: 'user' })
const productId = await brain.add("product456", { nounType: 'product' })
await brain.relate(userId, productId, "viewed", {
timestamp: Date.now()
})
@ -161,18 +161,18 @@ const similar = await brain.find({
```typescript
// Add entities (nouns) to the knowledge graph
const personId = await brain.addNoun("John Smith, Software Engineer", {
const personId = await brain.add("John Smith, Software Engineer", {
type: "person",
role: "engineer"
})
const companyId = await brain.addNoun("TechCorp, Innovation Leader", {
const companyId = await brain.add("TechCorp, Innovation Leader", {
type: "company",
industry: "technology"
})
// Create relationship
await brain.addVerb(personId, companyId, "works_at", {
await brain.relate(personId, companyId, "works_at", {
since: "2020",
position: "Senior Engineer"
})
@ -203,7 +203,7 @@ const brain = new BrainyData({
// Process streaming data
async function processStream(item) {
// Entity registry prevents duplicate nouns
const id = await brain.addNoun(item.content, {
const id = await brain.add(item.content, {
externalId: item.id,
timestamp: item.timestamp
})
@ -264,7 +264,7 @@ const brain = new BrainyData({
// Good - batch operations for nouns
const items = ["item1", "item2", "item3"]
for (const item of items) {
await brain.addNoun(item, { batch: true })
await brain.add(item, { batch: true })
}
// Create relationships efficiently
@ -273,7 +273,7 @@ const relationships = [
{ source: id2, target: id3, type: "similar" }
]
for (const rel of relationships) {
await brain.addVerb(rel.source, rel.target, rel.type)
await brain.relate(rel.source, rel.target, rel.type)
}
```
@ -307,7 +307,7 @@ const brain = new BrainyData({
```typescript
try {
await brain.addNoun("content", metadata)
await brain.add("content", metadata)
} catch (error) {
if (error.code === 'STORAGE_FULL') {
console.error('Storage is full')

View file

@ -302,7 +302,7 @@ const response = await openai.embeddings.create({
// After: Local Brainy embeddings
const brain = new BrainyData()
await brain.init() // One-time setup
const id = await brain.addNoun("Your text", 'content') // Embedded automatically
const id = await brain.add("Your text", { nounType: 'content' }) // Embedded automatically
```
### From Sentence Transformers

View file

@ -43,12 +43,12 @@ const clusters = await neural.clusters()
// Example: Organize customer feedback
const feedback = [
await brain.addNoun("The app crashes when I upload photos"),
await brain.addNoun("Photo upload feature is broken"),
await brain.addNoun("Great customer service!"),
await brain.addNoun("Support team was very helpful"),
await brain.addNoun("Pricing is too high"),
await brain.addNoun("Too expensive for what it offers")
await brain.add("The app crashes when I upload photos"),
await brain.add("Photo upload feature is broken"),
await brain.add("Great customer service!"),
await brain.add("Support team was very helpful"),
await brain.add("Pricing is too high"),
await brain.add("Too expensive for what it offers")
]
const themes = await neural.clusters()
@ -119,7 +119,7 @@ const neighbors = await neural.neighbors('item-id', 5)
// - data: The actual content
// Example: Recommend similar articles
const articleId = await brain.addNoun("Guide to React Hooks")
const articleId = await brain.add("Guide to React Hooks")
const similar = await neural.neighbors(articleId, 3)
for (const article of similar) {
@ -166,10 +166,10 @@ const outliers = await neural.outliers(0.3)
// Example: Detect spam or unusual content
const messages = [
await brain.addNoun("Meeting at 3pm"),
await brain.addNoun("Lunch plans for tomorrow"),
await brain.addNoun("BUY NOW!!! AMAZING DEALS!!!"),
await brain.addNoun("Project deadline next week")
await brain.add("Meeting at 3pm"),
await brain.add("Lunch plans for tomorrow"),
await brain.add("BUY NOW!!! AMAZING DEALS!!!"),
await brain.add("Project deadline next week")
]
const suspicious = await neural.outliers(0.4)
@ -238,7 +238,7 @@ const sameTopicArticles = currentTopic.members
// Add feedback with metadata
const feedbackIds = []
for (const feedback of customerFeedback) {
const id = await brain.addNoun(feedback.text, {
const id = await brain.add(feedback.text, {
rating: feedback.rating,
date: feedback.date,
product: feedback.product