Skip to content

Conversation

@RGBCube
Copy link

@RGBCube RGBCube commented Nov 21, 2025

Renamed the branch name of #698, so I had to re-create a PR. More changes & a better description coming soon (consult the original one for now)

Greptile Overview

Greptile Summary

Introduces Python and TypeScript DSL examples for HelixDB, demonstrating how to define schemas and queries programmatically as an alternative to HelixQL.

Major changes:

  • Added examples/bookstore.py with Python DSL showing nodes, vectors, edges, and query definitions
  • Added examples/bookstore.ts with equivalent TypeScript DSL implementation
  • Both examples include RAG use case with chapters, subchapters, and vector embeddings

Issues found:

  • Python file has 3 syntax errors that will prevent execution (forward reference, typo, missing prefix)
  • Python searchdocs_rag has logic bug - traverses wrong edge type
  • TypeScript has 1 syntax error (undefined variable)

The PR provides a promising foundation for language-native DSLs, but the examples need syntax fixes before they can serve as working references.

Important Files Changed

File Analysis

Filename Score Overview
examples/bookstore.py 2/5 Python DSL example with syntax errors (forward reference, typo) and logic bug in searchdocs_rag
examples/bookstore.ts 3/5 TypeScript DSL example with syntax error (missing hx. prefix on I64)

Sequence Diagram

sequenceDiagram
    participant User
    participant DSL as Python/TS DSL
    participant Schema as Schema Definition
    participant DB as HelixDB
    
    User->>DSL: Define Schema (Chapter, SubChapter nodes)
    DSL->>Schema: Register Node Types
    Schema->>DB: Create Node Type Definitions
    
    User->>DSL: Define Vector (SubChapterEmbedding)
    DSL->>Schema: Register Vector Type (1536 dims, cosine)
    Schema->>DB: Create Vector Index
    
    User->>DSL: Define Edge (Contains)
    DSL->>Schema: Register Edge Type (Chapter → SubChapter)
    Schema->>DB: Create Edge Type Definition
    
    User->>DSL: Call loaddocs_rag(chapters)
    DSL->>DB: AddN<Chapter>(index)
    DB-->>DSL: chapter_node
    
    loop For each subchapter
        DSL->>DB: AddN<SubChapter>(title, content, embedding)
        DB-->>DSL: subchapter_node
        DSL->>DB: AddE<Contains>(chapter → subchapter)
    end
    
    DSL-->>User: "Success"
    
    User->>DSL: Call searchdocs_rag(query, k)
    DSL->>DB: SearchV<Embedding>(query, k)
    DB-->>DSL: vectors
    DSL->>DB: Traverse edges (vectors → subchapters)
    DB-->>DSL: subchapter nodes
    DSL-->>User: {title, content} objects
Loading

@RGBCube RGBCube force-pushed the python-typescript-dsl branch from b66a103 to be34210 Compare November 21, 2025 18:01
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

const schema = hx.schema();

const Chapter = schema.defineNode({
index: I64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: I64 is undefined - should be hx.I64

Suggested change
index: I64,
index: hx.I64,
Prompt To Fix With AI
This is a comment left during a code review.
Path: examples/bookstore.ts
Line: 6:6

Comment:
**syntax:** `I64` is undefined - should be `hx.I64`

```suggestion
  index: hx.I64,
```

How can I resolve this? If you propose a fix, please make it concise.

title: helix.String
content: helix.String

embedding: SubChapterEmbedding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: SubChapterEmbedding used before definition (defined on line 72)

Suggested change
embedding: SubChapterEmbedding
class SubChapterEmbedding(db.Vector(dimensions=1536, hnsw=helix.cosine)):
pass
class SubChapter(db.Node):
title: helix.String
content: helix.String
embedding: SubChapterEmbedding
Prompt To Fix With AI
This is a comment left during a code review.
Path: examples/bookstore.py
Line: 70:70

Comment:
**syntax:** `SubChapterEmbedding` used before definition (defined on line 72)

```suggestion
class SubChapterEmbedding(db.Vector(dimensions=1536, hnsw=helix.cosine)):
    pass

class SubChapter(db.Node):
    title: helix.String
    content: helix.String

    embedding: SubChapterEmbedding
```

How can I resolve this? If you propose a fix, please make it concise.


class ArgChapter(helix.Struct):
id: helix.I64
subchapters: helix.List[ArgSubchapter]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: ArgSubchapter is defined on line 82 but referenced here as ArgSubChapter (capital C)

Suggested change
subchapters: helix.List[ArgSubchapter]
subchapters: helix.List[ArgSubchapter]
Prompt To Fix With AI
This is a comment left during a code review.
Path: examples/bookstore.py
Line: 80:80

Comment:
**syntax:** `ArgSubchapter` is defined on line 82 but referenced here as `ArgSubChapter` (capital C)

```suggestion
    subchapters: helix.List[ArgSubchapter]
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +104 to +108
def searchdocs_rag(query: helix.Vector, k: helix.I32) -> helix.Iterator[helix.Map[helix.String, helix.Value]]:
# TODO
vecs = db.search_vector(query, k)
chapters = vecs.incoming_nodes[Contains]
return chapters.map(lambda c: {"index": c.index})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: logic doesn't match the commented HelixQL query above (lines 43-46) - should get subchapters from vectors via EmbeddingOf edge, not chapters via Contains

Prompt To Fix With AI
This is a comment left during a code review.
Path: examples/bookstore.py
Line: 104:108

Comment:
**logic:** logic doesn't match the commented HelixQL query above (lines 43-46) - should get `subchapters` from vectors via `EmbeddingOf` edge, not `chapters` via `Contains`

How can I resolve this? If you propose a fix, please make it concise.

@RGBCube RGBCube force-pushed the python-typescript-dsl branch from be34210 to 1a6df2c Compare November 21, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants